set_error_handler() 对致命错误不起作用

2021-12-26 00:00:00 error-handling php fatal-error

我有一个简单的自定义错误处理程序,可以在错误日志文件中写入一些有用的调试信息.

I have a simple custom error handler that writes in a error log file some useful debug infos.

它适用于所有情况,但不会因 FATAL 错误而触发.

it's work for everything but it's not get triggered for FATAL error.

有什么办法可以解决这个问题吗?

Any way to solve this?

目前为了绕过这种情况,我也注册了一个关闭函数来检查error_get_last()

Currently to bypass this circumstance I have registered a shutdown function too that checks error_get_last()

推荐答案

不,那只是 set_error_handler();它不会处理所有错误.

Nope, that's just a limitation of set_error_handler(); it doesn't handle all errors.

用户定义的函数无法处理以下错误类型:E_ERRORE_PARSEE_CORE_ERRORE_CORE_WARNINGE_COMPILE_ERRORE_COMPILE_WARNING 和大部分 E_STRICT 在调用 set_error_handler() 的文件中提出.

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

register_shutdown_function()error_get_last() 是一个不错的解决方法.

The register_shutdown_function() and error_get_last() is a decent workaround.

相关文章