dongtuan1594 2013-09-11 19:18
浏览 6
已采纳

在运行时检查自定义PHP错误处理程序

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?

  • 写回答

1条回答 默认 最新

  • dongxiansi0158 2013-09-11 19:26
    关注

    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";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?