PHP restore_error_handler() Function
The PHP restore_error_handler() function restores the previous error handler function. This function is used after changing the error handler function using set_error_handler(), to revert to the previous error handler (which could be the built-in or a user defined function).
Syntax
restore_error_handler()
Parameters
No parameter is required.
Return Value
Always returns true.
Example: restore_error_handler() example
The example below shows the usage of restore_error_handler() function.
<?php //a user-defined error handler function function myErrorHandler($errno, $errstr, $errfile, $errline) { echo "<b>My ERROR</b> [$errno] $errstr<br>\n"; echo "Error on line $errline in file $errfile<br>\n"; echo "Aborting...<br>\n"; } //setting user-defined error handler function set_error_handler("myErrorHandler"); $test = 100; //triggering user-defined error handler function if ($test==100) { trigger_error("A custom error has been triggered"); } //restoring the previous (built-in) error handler restore_error_handler(); ?>
The output of the above code will be:
My ERROR [1024] A custom error has been triggered Error on line 20 in file index.php Aborting...
❮ PHP Error Handling Reference