restore_exception_handler()
restore_exception_handler() — Restores the previously defined exception handler function.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
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).
Signature
restore_exception_handler(): true
Parameters
This function takes no parameters.
Return value
Always returns true.
Example
A runnable snippet:
function exception_handler_1(Exception $e) { echo '[' . __FUNCTION__ . '] ' . $e->getMessage(); } function exception_handler_2(Exception $e) { echo '[' . __FUNCTION__ . '] ' . $e->getMessage(); } set_exception_handler('exception_handler_1'); set_exception_handler('exception_handler_2'); restore_exception_handler(); throw new Exception('This triggers the first exception handler...');
Output:
[exception_handler_1] This triggers the first exception handler...
Changelog
| Version | Change |
|---|---|
| 8.3.5 | The exception handler being invoked is now pushed onto the handler stack, so restore_exception_handler() called from within an exception handler re-installs the handler that is currently running; restoring the handler that was active before it now requires two calls. |
| 8.3.0 | The active exception handler is now unset while it runs. |
See also
set_exception_handler(), get_exception_handler(), set_error_handler(), restore_error_handler(), error_reporting()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page restore_exception_handler() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.