gpt4 book ai didi

php - register_shutdown_function() 仍然输出原始错误信息

转载 作者:可可西里 更新时间:2023-11-01 13:26:39 26 4
gpt4 key购买 nike

我正在尝试用自定义函数替换内置的 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");

?>

有什么想法吗?

最佳答案

正如评论中已经提到的,register_shutdown_function 的使用不会覆盖内置的错误处理(同样 set_error_handler 也不会)。

如果您不想看到原始消息,请在您的 php.ini 中使用 display_errors = 0 禁用它们的输出。或者在您的脚本中使用 ini_set('display_errors', 0); 即时运行。

关于php - register_shutdown_function() 仍然输出原始错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13952328/

26 4 0
文章推荐: angularjs - 使用 $index 在 ng-repeat 中间添加
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com