PHP restore_error_handler() Function

PHP restore_exception_handler() Function
PHP error_reporting() Function

In this article, you will learn how to get the previous error handler in PHP. The restore_error_handler() function in PHP restores the previous error handler. This function is used to restore the previous error handler after changing it with the set_error_handler() function.

what is the syntax of the RESTORE_ERROR_HANDLER() function in php?

restore_error_handler();

examples of the RESTORE_ERROR_HANDLER() function

Example 1. In this example, we 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");
}
?>
PHP restore_exception_handler() Function
PHP error_reporting() Function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top