PHP restore_exception_handler() Function
The PHP restore_exception_handler() function restores the previously defined exception handler function. This function is used after changing the exception handler function using set_exception_handler(), to revert to the previous exception handler (which could be the built-in or a user defined function).
Syntax
restore_exception_handler()
Parameters
No parameter is required.
Return Value
Always returns true.
Example: restore_exception_handler() example
The example below shows the usage of restore_exception_handler() function.
<?php //two user-defined exception handler functions function myException1($e) { echo "[".__FUNCTION__ ."]: ".$e->getMessage(); } function myException2($e) { echo "[".__FUNCTION__."]: ".$e->getMessage(); } //sets myException1 as exception handler function set_exception_handler("myException1"); //sets myException2 as exception handler function set_exception_handler("myException2"); //restore the previous exception handler function //which is myException1 restore_exception_handler(); //throw exception throw new Exception("This triggers the first exception handler..."); ?>
The output of the above code will be:
[myException1]: This triggers the first exception handler...
❮ PHP Error Handling Reference