4

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.

The http status code returned is 200.

"display_errors" is set to "On" and "error_reporting" to "E_ALL" in the php.ini file. 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.).

Does anyone know where the second output of the notice comes from? And especially how the get rid of it?

4
  • The script turns on the error reporting for php scripts. See the file test.php on line 3 for the error. Commented Apr 1, 2014 at 15:32
  • No idea about IIS but command-line PHP prints error messages to both stdout and stderr. That seems to be the case as well for your web server set up. Commented Apr 1, 2014 at 15:47
  • have u tried by commenting the first line error_reporting(E_ALL);. Commented Apr 2, 2014 at 10:12
  • Yes I tried to commenting it out. But the error_reporting function just defines which error types (levels) will be outputed not if they realy be send as output. The display_errors directive defines that. Commented Apr 2, 2014 at 10:24

3 Answers 3

2

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

Notice: Undefined variable: test in /path/to/script.php on line 8

Try turning one or the other off or a set a custom error handler.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Sorry but that's not true. The "error_reporting()" function does not output anything, it just overwrites the "error_reporting" directive set in the php.ini. And it does not cause the second output.
0

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! I still don't know why, but at least it works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.