如果我执行以下脚本:
<?php
error_reporting(E_ALL);
trigger_error('test notice', E_USER_NOTICE);
die('end of script');
我得到以下输出:
<br />
<b>Notice</b>: test notice in <b>path/to/script/test.php</b> on line <b>3</b><br />
end of scriptPHP Notice: test notice in path/to/script/test.php on line 3
脚本在 IIS8 上执行,PHP 版本为 5.4.19。
返回的http状态码为200。
在 php.ini 文件中,“display_errors”设置为“On”,“error_reporting”设置为“E_ALL”。所以脚本的第一行只是为了说明。
行为与所有错误报告常量(E_ERROR、E_WARNING 等)相同。
有谁知道通知的第二个输出是从哪里来的?尤其是如何摆脱它?
最佳答案
如果你同时设置了
error_reporting(E_ALL);
ini_set('display_errors', 1);
错误会加倍:
PHP Notice: Undefined variable: test in /path/to/script.php on line 8
Notice: Undefined variable: test in /path/to/script.php on line 8
尝试关闭其中一个或关闭一个 set a custom error handler .
关于PHP:双重输出 php 错误/警告/通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22790306/