PHP restore_error_handler() Function

PHP Error Reference

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");
}
?>
Try it Yourself »

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
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.