Home >Backend Development >PHP Tutorial >php restore_error_handler() function and restore_exception_handler() function
restore_error_handler — Restore the previous error handling Function
Description
bool restore_error_handler ( void )
Change the error using set_error_handler() After handling the function, this function can be used to restore the previous error handler (either a built-in or a user-defined function).
Return value
This function always returns TRUE.
restore_error_handler() example
If unserialize() causes an error, the original error handling function will be restored.
<?php function unserialize_handler ( $errno , $errstr ) { echo "Invalid serialized value.\n" ; } $serialized = 'foo' ; set_error_handler ( 'unserialize_handler' ); $original = unserialize ( $serialized ); restore_error_handler (); ?>
The above routine will output:
Invalid serialized value.
restore_exception_handler - Restore the previously defined Exception handling function.
Description
bool restore_exception_handler ( void )
After using set_exception_handler() to change the exception handling function, this function can be used to restore the previous exception handler (can be built-in or is a user-defined function).
Return value
This function always returns TRUE.
restore_exception_handler() function example
<?php 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...' ); ?>
The above routine will output:
[exception_handler_1] This triggers the first exception handler...
The above is the detailed content of php restore_error_handler() function and restore_exception_handler() function. For more information, please follow other related articles on the PHP Chinese website!