Skip to content

Commit

Permalink
report diagnostic messages on standard error
Browse files Browse the repository at this point in the history
PHP diagnostic messages do not interfere any longer with the standard
output of the auto-completion.

whatever the setting of display_errors [1] is, set it to the string
"stderr" (as of PHP 5.2.4) to send errors to the standard error stream [2],
always,  the stream for writing diagnostic output.

this is specifically important as the `symfony-autocomplete` command writes
conventional output to standard output and some _default_ php (incl. cli)
configurations display errors on standard output,  too,  interleaving the
conventional output with error information which renders it flawed.

this did affect the Dockerhub `php` official image (php:8.1-cli-alpine) [3]
and was confirmed with php8.1-cli sury debian package.

usage example (php8.1 -n -f ...):

    $ symfony-autocomplete --shell=bash --aliases=codecept \
        > /etc/bash_completion.d/composer
    Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mot/PhpstormProjects/symfony-console-autocomplete/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php on line 104

PHP diagnostic messages (error, warning, deprecation etc.) are now shown
on standard error - even if not before - according to the error reporting
level [4] of the PHP cli run-time configuration.

php-language-level: 8.1
issue: 72
credits: Alberto Tavoletti (sviluppo; reporting and testing)
[1]: https://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
[2]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_05
[3]: https://hub.docker.com/_/php
[4]: https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
  • Loading branch information
ktomk committed Apr 11, 2022
1 parent 174a960 commit 5adeafb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/symfony-autocomplete
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env php
<?php

if (function_exists('ini_set')) {
// utility errors on standard error
ini_set('display_errors', 'stderr');
}

if (file_exists($autoload = __DIR__.'/../../../autoload.php')) {
require_once $autoload;
Expand Down

0 comments on commit 5adeafb

Please sign in to comment.