我试图用自定义的替换内置的php shutdown_function.
它完美地工作,但是,它仍然在我的新错误消息之上输出原始错误(内置错误).
<?php
function shutdown_output() {
$error = error_get_last();
if($error !== NULL) {
echo "ERROR";
exit();
} else {
echo "NO ERROR";
}
}
// Set the error reporting:
register_shutdown_function('shutdown_output');
// test.php does not exist, just here to get a critical error
require_once("test.php");
?>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
正如评论中已经提到的,使用register_shutdown_function不会覆盖内置错误处理(同样的方式也set_error_handler不会覆盖)。
如果您不想看到原始消息,请在您的php.iniusing中禁用它们的输出display_errors = 0。或者在您的脚本中使用ini_set('display_errors', 0);.