請注意,這在例外處理函式內部無效。
例如:
<?php
函式 handler1(Exception $e) {
echo "handler1\n";
restore_exception_handler();
throw $e;
}
函式 handler2(Exception $e) {
echo "handler2\n";
}
set_exception_handler( 'handler2' );
set_exception_handler( 'handler1' );
throw new Exception( '可能會預期看到 handler1, handler2' );
/* 輸出:
handler1
PHP 致命錯誤:未捕獲的例外 'Exception',訊息為 '可能會預期看到 handler1, handler2',位於 /tmp/demo.php:15
堆疊追蹤:
#0 {main}
拋出於 /tmp/demo.php 的第 15 行
*/
?>