php restore_error_handler() function and restore_exception_handler() function

怪我咯
Release: 2023-03-13 12:10:02
Original
1319 people have browsed it

restore_error_handler — Restore the previous error handling Function

Description

bool restore_error_handler ( void )
Copy after login

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 ();
?>
Copy after login

The above routine will output:

Invalid serialized value.
Copy after login

restore_exception_handler - Restore the previously defined Exception handling function.

Description

bool restore_exception_handler ( void )
Copy after login

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; );
?>
Copy after login

The above routine will output:

[exception_handler_1] This triggers the first exception handler...
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template