首頁  >  文章  >  後端開發  >  php restore_error_handler()函數與restore_exception_handler()函數

php restore_error_handler()函數與restore_exception_handler()函數

怪我咯
怪我咯原創
2017-07-11 09:16:201267瀏覽

restore_error_handler — 還原之前的錯誤處理函數

說明

bool restore_error_handler ( void )

在使用 #set_error_handler#() 改變錯誤處理函數之後,此函數可以用來還原先前的錯誤處理程序(可以是內建的或也可以是使用者定義的函數)。

傳回值

該函數總是回傳 TRUE 。

 restore_error_handler() 實例

如果是 unserialize() 導致了一個錯誤,接下來 會恢復原來的錯誤處理函數。

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

以上例程會輸出:

Invalid serialized value.

restore_exception_handler — 還原先前定義過的異常處理函數。

說明

bool restore_exception_handler ( void )

在使用set_exception_handler() 改變異常處理函數之後,此函數可以用於還原之前的異常處理程序(可以是內建的或也可以是使用者所定義的函數)。

傳回值

該函數總是傳回 TRUE 。

restore_exception_handler()函數實例

<?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; );
?>

以上程式會輸出:

[exception_handler_1] This triggers the first exception handler...

以上是php restore_error_handler()函數與restore_exception_handler()函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn