Unsigned
Unsigned

Reputation: 9916

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:

Why does Off not turn off error display on stdout?

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

Upvotes: 5

Views: 5709

Answers (1)

Gergo Erdosi
Gergo Erdosi

Reputation: 42048

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.

Upvotes: 12

Related Questions