【发布时间】:2010-11-20 00:19:55
【问题描述】:
请告诉我这是否正确。在我的错误处理程序中,我需要能够检测到 @error-control 运算符何时用于抑制错误,因为一些外部库(可悲的是)经常使用它。应该继续执行脚本,就像您不使用自定义错误处理程序一样。
当使用 at 符号时,PHP 临时将 error_reporting 设置为 0。因此,在脚本开始时,我们将 error_reporting 设置为除零以外的任何值——我们现在可以做一些漂亮的 IF/ELSE 魔术。为了避免在前端显示任何错误,我们还将 display_errors 设置为 0,这将覆盖 error_reporting(但我们仍然可以将其值用于魔术)。
<?php
ini_set('display_errors',0);
error_reporting(E_ALL);
function error_handler($errno, $errstr, $errfile, $errline)
{
if (error_reporting()===0) return;
else die();
}
set_error_handler('error_handler');
//This issues an error, but the handler will return and execution continues.
//Remove the at-sign and the script will die()
@file();
echo 'Execution continued, hooray.';
?>
所以.. 这里没有问题吗?除了外部库覆盖我的错误处理的那个..(有什么提示吗?)
【问题讨论】:
标签: php error-handling