restore_exception_handler関数
関数 restore_exception_handler は、set_exception_handler を使用して置き換えられた以前の例外ハンドラを復元します。
この関数はパラメータを受け取らず、値を返しません。
構文
restore_exception_handler();
例
カスタム例外ハンドラを設定し、その後、以前のハンドラを復元してみましょう:
<?php
function customExceptionHandler($exception) {
echo 'Custom handler: ' . $exception->getMessage();
}
set_exception_handler('customExceptionHandler');
restore_exception_handler();
?>
例
復元後、標準のメカニズムが機能することを確認します:
<?php
set_exception_handler(function($exception) {
echo 'Handler 1: ' . $exception->getMessage();
});
set_exception_handler(function($exception) {
echo 'Handler 2: ' . $exception->getMessage();
});
restore_exception_handler();
throw new Exception('Test error');
?>
コード実行結果:
'Handler 1: Test error'