PHP restore_error_handler() Function
Example
Restore the previous error handler after changing it with the set_error_handler() function:
<?php
// A user-defined error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline) {
echo "<b>Custom error:</b> [$errno] $errstr<br>";
echo " Error on line $errline in $errfile<br>";
}
// Set user-defined error handler function
set_error_handler("myErrorHandler");
$test=2;
// Trigger error
if ($test>1) {
trigger_error("A custom error has been triggered");
}
// Restore previous error handler
restore_error_handler();
// Trigger error again
if ($test>1) {
trigger_error("A custom error has been triggered");
}
?>
The above code will output something like this:
Custom error: [1024] A custom error has been triggered
Error on line 14 in C:\webfolder\test.php
Notice: A custom error has been triggered in
C:\webfolder\test.php on line 21
Definition and Usage
The restore_error_handler() function restores the previous error handler.
This function is used to restore the previous error handler after changing it with the set_error_handler() function.
Tip: The previous error handler could be the built-in error handler or a user-defined error handler function.
Syntax
restore_error_handler();
Technical Details
Return Value: | Always TRUE |
---|---|
PHP Version: | 4.0.1+ |
PHP Error Reference