PHP:php错误/警告/通知的双重输出


PHP: double output of php errors / warnings / notices

如果我执行以下脚本:

<?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

该脚本在 IIS 8 上使用 PHP 版本 5.4.19 执行。

返回的 http 状态代码为 200。

"display_errors"在 php.ini 文件中设置为"On",将"error_reporting"设置为 "E_ALL"。所以脚本的第一行只是为了澄清。

所有错误报告常量(E_ERROR、E_WARNING等)的行为都是相同的。

有谁知道通知的第二个输出来自哪里?尤其是如何摆脱它?

如果同时设置两者

error_reporting(E_ALL);
ini_set('display_errors', 1);

错误将加倍:

PHP 注意:未定义的变量:测试 /path/to/script.php 在第 8 行

注意:未定义的变量:测试 /path/to/script.php 在第 8 行

尝试关闭其中一个或设置自定义错误处理程序。

脚本的第一行

error_reporting(E_ALL);
将 PHP 设置为报告所有错误,并在 PHP 配置中启用display_errors指令,该指令将 PHP 设置为将错误打印到屏幕上,然后无需复制输出的第二行。

为了解决这个问题,我不得不在IIS中更改站点的基本设置:与IIS_USER的"连接为"和 php 错误消息的双重输出消失了!我仍然不知道为什么,但至少它有效。