简体   繁体   English

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

[英]PHP: double output of php errors / warnings / notices

If I execute the following script: 如果我执行以下脚本:

<?php
error_reporting(E_ALL);
trigger_error('test notice', E_USER_NOTICE);
die('end of script');

I get the following output: 我得到以下输出:

<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

The script was executed on IIS8 with PHP Version 5.4.19. 该脚本在IIS8上使用PHP版本5.4.19执行。

The http status code returned is 200. 返回的http状态代码是200。

"display_errors" is set to "On" and "error_reporting" to "E_ALL" in the php.ini file. 在php.ini文件中,“display_errors”设置为“On”,“error_reporting”设置为“E_ALL”。 So the first line of the script is just for clarification. 所以脚本的第一行只是为了澄清。

The behaviour is the same with all error reporting constants (E_ERROR, E_WARNING, etc.). 所有错误报告常量(E_ERROR,E_WARNING等)的行为都相同。

Does anyone know where the second output of the notice comes from? 有谁知道通知的第二个输出来自哪里? And especially how the get rid of it? 特别是如何摆脱它?

If you set both 如果你设置两者

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

The errors will be doubled: 错误将加倍:

PHP Notice: Undefined variable: test in /path/to/script.php on line 8 PHP注意:未定义的变量:在第8行的/path/to/script.php中测试

Notice: Undefined variable: test in /path/to/script.php on line 8 注意:未定义的变量:在第8行的/path/to/script.php中测试

Try turning one or the other off or a set a custom error handler . 尝试关闭一个或另一个或设置自定义错误处理程序

First line in your script 脚本中的第一行

error_reporting(E_ALL);
Sets PHP to report all errors and with display_errors directive enabled in your PHP configuration which sets PHP to print errors to the screen, then no need to your second line which duplicates the output. 将PHP设置为报告所有错误,并在PHP配置中启用display_errors指令,将PHP设置为打印错误到屏幕,然后不需要第二行复制输出。

To solve this issue I had to change the base settings of the site in IIS: "Connect As" with the IIS_USER and the double output of php error messages were gone! 要解决此问题,我必须在IIS中更改站点的基本设置:“连接为”与IIS_USER,并且php错误消息的双输出消失了! I still don't know why, but at least it works. 我仍然不知道为什么,但至少它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM