Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error reporting behavior in CLI binary

test.php contains the following line:

<?php echo 1 / 0; ?>

PHP version is 5.4.0 (cli)

Now, a series of tests with display_errors:

  • display_errors = Off image1
  • display_errors = stderr image2
  • display_errors = stdout image3

Why does Off not turn off error display on stdout?

Why do both stdout and stderr end up printing to both outputs simultaneously?

like image 710
Unsigned Avatar asked May 27 '12 05:05

Unsigned


1 Answers

Why does Off not turn off error display on stdout?

I suppose because error_log is not set. If it is set, errors are not displayed. If it not set, PHP will use the SAPI error logger, which is stderr (= stdout) in CLI. See:

ini_set('display_errors', 0);
echo 1 / 0; // Prints a warning.

ini_set('error_log', '/dev/null');
echo 1 / 0; // No warning on the standard output.

Why do both stdout and stderr end up printing to both outputs simultaneously?

The first error was sent to the SAPI error logger, the second was sent to stdout (display_errors = on). Both messages are displayed because as I mentioned above, the SAPI error logger is stderr, which is also stdout in this case.

like image 97
Gergo Erdosi Avatar answered Sep 20 '22 14:09

Gergo Erdosi