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

怪我咯
發布: 2023-03-13 12:10:02
原創
1266 人瀏覽過

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中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!