Home  >  Article  >  Backend Development  >  php restore_error_handler() function and restore_exception_handler() function

php restore_error_handler() function and restore_exception_handler() function

怪我咯
怪我咯Original
2017-07-11 09:16:201318browse

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  =  &#39;foo&#39; ;
set_error_handler ( &#39;unserialize_handler&#39; );
$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  &#39;[&#39;  .  FUNCTION  .  &#39;] &#39;  .  $e -> getMessage ();
    }

    function  exception_handler_2 ( Exception $e )
    {
        echo  &#39;[&#39;  .  FUNCTION  .  &#39;] &#39;  .  $e -> getMessage ();
    }

     set_exception_handler ( &#39;exception_handler_1&#39; );
     set_exception_handler ( &#39;exception_handler_2&#39; );

     restore_exception_handler ();

    throw new  Exception ( &#39;This triggers the first exception handler...&#39; );
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn