Instance
Set the user-defined error handler through the Set_error_handler () function and then trigger the error (via Trigger_error ()):
User-defined error handler function MyErrorHandler ($errno, $errstr, $errfile, $errline) { echo ' <b>custom error:</b > [$errno] $errstr <br> "; //Trigger error if ($test >1) {
The output of the above code is similar to this:
Custom error: [1024x768] A custom error has been triggered error on line + in C:\webfolder\test.php
Definition and usage
The Set_error_handler () function sets the user-defined error-handling function.
Note: If you use this function, the standard PHP error handler is bypassed, and if necessary, the user-defined error program terminates the script through Die ().
Note: If an error occurs before the script executes (such as when a file is uploaded), the custom error handler will not be called because it is not yet registered at that time.
Grammar
Set_error_handler (ErrorHandler, e_all| E_STRICT);
| Parameters |
Description |
| ErrorHandler |
Necessary. Specifies the name of the user error handler function. |
| e_all| E_strict |
Optional. Specifies which error report level user-defined error is displayed. The default is "E_all". |
Technical details
| return value: |
A string that contains the error handler that was previously defined. |
| PHP version: |
4.0.1+ |
| PHP Update log: |
PHP 5.5: Parameter errorhandler now accepts NULL
PHP 5.2: The error handler must return FALSE to display the $php _errormsg. |
PHP Set_error_handler () function