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

时间:2014-04-01 15:29:28

标签: php error-reporting

如果我执行以下脚本:

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

&#34;的display_errors&#34;设置为&#34; On&#34;和&#34; error_reporting&#34;到&#34; E_ALL&#34;在php.ini文件中。所以脚本的第一行只是为了澄清。

行为与所有错误报告常量(E_ERROR,E_WARNING等)相同。

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

3 个答案:

答案 0 :(得分:2)

如果同时设置

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

错误将加倍:

  

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

     

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

尝试关闭其中一个或set a custom error handler

答案 1 :(得分:0)

脚本中的第一行

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

答案 2 :(得分:0)

要解决此问题,我必须在IIS中更改站点的基本设置: &#34; Connect As&#34;与IIS_USER和PHP错误消息的双输出都消失了! 我仍然不知道为什么,但至少它是有效的。