简体   繁体   中英

Check, at Runtime, for a Custom PHP Error Handler

Is there any way to check, at runtime, if a custom PHP error handler has been set?

That is, the PHP function set error handler allows you to set a custom function/callback to handle PHP errors. However, there's no corresponding get_error_handler function.

Does PHP have any system for checking this at runtime? If there's no official API for doing this, is there any tricky way of determining this via code?

You can set your own error handler, and get return value of set_error_handler - if it is null there was no error handler defined:

$last_error_handler = set_error_handler(function(){});
if ($last_error_handler === null) {
    restore_error_handler();
} else {
    // Set it back to what was defined
    set_error_handler($last_error_handler);
    echo "Found";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM