Php register_shutdown_function()仍输出原始错误消息
我试图用一个自定义函数替换内置的php shutdown_函数 它工作得很好,但是,它仍然在我的新错误消息上方输出原始错误(内置错误)Php register_shutdown_function()仍输出原始错误消息,php,Php,我试图用一个自定义函数替换内置的php shutdown_函数 它工作得很好,但是,它仍然在我的新错误消息上方输出原始错误(内置错误) <?php function shutdown_output() { $error = error_get_last(); if($error !== NULL) { echo "ERROR"; exit(); } else { echo "NO ERR
<?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");
?>
有什么想法吗?正如在评论中已经提到的,使用
注册关闭功能不会覆盖内置的错误处理(与设置错误处理程序
的方式相同)
如果不想看到原始消息,请使用display\u errors=0
在php.ini
中禁用它们的输出。或者在脚本中使用ini\u集(“显示错误”,0)代码>如果您没有关闭PHP自己的错误报告,这并不奇怪。您还必须设置错误报告(0)代码>和ini\u集('display\u errors',0)
不输出原始错误消息。“与设置错误处理程序
的方式相同”:但表示:“对于错误类型
指定的错误类型,标准PHP错误处理程序被完全绕过,除非回调函数返回FALSE
”?@AlvinWong也许我所说的是误导性的,set\u error\u handler
只处理E\u USER.*
(以及一些其他)错误,在其他情况下会使用默认的处理程序。