【发布时间】:2013-05-08 20:42:14
【问题描述】:
有什么方法可以查明这个警告是否被抑制或没有使用 set_error_handler() 函数? @somethingwrong() 和 somethingwrong() 的代码为 2。但我不想记录所有警告。例如,像 gzuncompress() 这样的一些函数必须以这种方式处理,因为我无法测试有效的输入数据。
$handler = new errorHandler();
error_reporting(0);
set_error_handler(array($handler, 'handle'));
set_exception_handler(array($handler, 'exception'));
register_shutdown_function(array($handler, 'shutdown'));
class errorHandler
{
public function handle($code, $text, $file, $line)
{
if (($code & (E_STRICT | E_NOTICE)) == 0)
$this->log(...);
}
public function exception($exception)
{
...
}
public function shutdown()
{
$e = error_get_last();
if ($e !== NULL)
$this->log($error);
}
}
// the errors
include('notexisting.file'); // should be logged
@gzuncompress('somenonsens'); // should not be logged
【问题讨论】:
-
您要禁止显示哪个“此警告”?使用 error_reporting(0) 可以禁用错误报告。也许您的意思是 error_reporting(-1) 或类似的? @somethingwrong() 的代码 2 是什么?请澄清您的问题。
-
正如您在 php.net 上看到的,代码 2 用于 E_WARNING,4 用于 E_PARSE,...如果您说它正在禁用,那么为什么它仍然会记录所有错误?但它关闭了显示错误。现在我写了 ini_set('display_errors','Off');错误报告(-1);效果是一样的。
标签: php suppress-warnings ierrorhandler at-sign