PHP E_USER_ERROR

The E_USER_ERROR is a custom error that can be triggered by developers when coding.

1309 views
d

By. Jacob

Edited: 2020-02-25 15:33

E_USER_ERROR in PHP.

E_USER_ERROR is a user-defined error type in PHP that can be triggered by developers from within their scripts. To trigger a user-error, we may use the trigger_error function in a script.

We may only trigger the E_USER_* error types with trigger_error. When an error is triggered, it will function similarly to PHP's build-in errors, and if logging is enabled it will also get written to the server log.

The E_USER_ERROR is intended for non-recoverable errors, similar to E_ERROR errors thrown by PHP.

E_USER_ERROR will also be handled by a custom error handler if defined.

Note. It is probably better to throw an exception rather than relying too much on triggering errors. The trigger_error(); function may still have uses, such as informing of deprecated features by triggering E_USER_DEPRECATED.

To trigger a E_USER_ERROR, we can do like shown below:

trigger_error("A required file did not exist!", E_USER_ERROR);

Tell us what you think:

  1. In this Tutorial, it is shown how to redirect all HTTP requests to a index.php file using htaccess or Apache configuration files.
  2. How to create a router in PHP to handle different request types, paths, and request parameters.
  3. Tutorial on how to use proxy servers with cURL and PHP
  4. When using file_get_contents to perform HTTP requests, the server response headers is stored in a reserved variable after each successful request; we can iterate over this when we need to access individual response headers.
  5. How to effectively use variables within strings to insert bits of data where needed.

More in: PHP Tutorials