ฟังก์ชัน restore_exception_handler
ฟังก์ชัน restore_exception_handler ทำการกู้คืนตัวจัดการข้อยกเว้นก่อนหน้า,
ที่ถูกแทนที่ด้วย set_exception_handler ฟังก์ชันนี้ไม่รับพารามิเตอร์
และไม่ส่งคืนค่า
ไวยากรณ์
restore_exception_handler();
ตัวอย่าง
มาตั้งค่าตัวจัดการข้อยกเว้นแบบกำหนดเอง แล้วกู้คืนตัวจัดการก่อนหน้ากลับมา:
<?php
function customExceptionHandler($exception) {
echo 'ตัวจัดการแบบกำหนดเอง: ' . $exception->getMessage();
}
set_exception_handler('customExceptionHandler');
restore_exception_handler();
?>
ตัวอย่าง
มาตรวจสอบว่าหลังจากการกู้คืนตัวจัดการ กลไกมาตรฐานทำงาน:
<?php
set_exception_handler(function($exception) {
echo 'ตัวจัดการ 1: ' . $exception->getMessage();
});
set_exception_handler(function($exception) {
echo 'ตัวจัดการ 2: ' . $exception->getMessage();
});
restore_exception_handler();
throw new Exception('ข้อผิดพลาดทดสอบ');
?>
ผลลัพธ์จากการรันโค้ด:
'ตัวจัดการ 1: ข้อผิดพลาดทดสอบ'