Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน restore_exception_handler() ใน PHP

คำอธิบาย

ฟังก์ชัน restore_exception_handler() คืนค่าตัวจัดการข้อยกเว็น (exception handler) กลับไปเป็นตัวจัดการก่อนหน้า

รูปแบบการใช้งาน (Syntax)

restore_exception_handler()

พารามิเตอร์

ไม่มีพารามิเตอร์

ค่าที่คืนกลับ

คืนค่า TRUE เสมอ

ตัวอย่างการใช้งาน

<?php
function customException1($exception) {
    echo "[" . __FUNCTION__ . "] " . $exception->getMessage();
}
function customException2($exception) {
    echo "[" . __FUNCTION__ . "] " . $exception->getMessage();
}
function customException3($exception) {
    echo "[" . __FUNCTION__ . "] " . $exception->getMessage();
}

set_exception_handler("customException1");
set_exception_handler("customException2");
set_exception_handler("customException3");
restore_exception_handler();

// โยนข้อยกเว้น - จะถูกจับโดย customException1
throw new Exception("Triggers the first exception handler!");
?>

ผลลัพธ์

[customException1] Triggers the first exception handler!