PHP_CodeSniffer: php errors should go to stderr, too
Describe the bug PHP errors should also go to stderr not stdout.
Current behaviour breaks external tools calling phpcs - these expect json and not mix of json with errors
Code sample + To reproduce
Current behaviour::
% echo test | /usr/local/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 --stdin-path=/somewhere.php
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
{"totals":{"errors":0,"warnings":1,"fixable":0},"files":{"\/somewhere.php":{"errors":0,"warnings":1,"messages":[{"message":"No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.","source":"Internal.NoCodeFound","severity":5,"fixable":false,"type":"WARNING","line":1,"column":1}]}}}
Fortunately PHP supports displaying errors to stderr:
echo test | /usr/local/bin/php -d display_errors="stderr" /usr/local/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 --stdin-path=/somewhere.php
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Files\FileList::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Files/FileList.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::getChildren() should either be compatible with RecursiveFilterIterator::getChildren(): ?RecursiveFilterIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
PHP Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
Deprecated: Return type of PHP_CodeSniffer\Filters\Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///usr/local/Cellar/php-code-sniffer/3.6.1/bin/phpcs/src/Filters/Filter.php on line 2
{"totals":{"errors":0,"warnings":1,"fixable":0},"files":{"\/somewhere.php":{"errors":0,"warnings":1,"messages":[{"message":"No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.","source":"Internal.NoCodeFound","severity":5,"fixable":false,"type":"WARNING","line":1,"column":1}]}}}
which will help these tools since they parse stdout only:
% echo test | /usr/local/bin/php -d display_errors="stderr" /usr/local/bin/phpcs --report=json -q --encoding=UTF-8 --error-severity=5 --warning-severity=5 --stdin-path=/somewhere.php 2> /dev/null
{"totals":{"errors":0,"warnings":1,"fixable":0},"files":{"\/somewhere.php":{"errors":0,"warnings":1,"messages":[{"message":"No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.","source":"Internal.NoCodeFound","severity":5,"fixable":false,"type":"WARNING","line":1,"column":1}]}}}
so please set display errors to stderr in phpcs. Would complete #1612
Versions (please complete the following information):
- OS: MacOS 12.0.1
- PHP: 8.1 (could be unsupported with current phpcs but above is generic behaviour and just deprecation errors from 8.1 are an example)
- PHPCS: 3.6.1
- Standard: default
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 19 (8 by maintainers)
All squared up over on Homebrew, and I can confirm it installs the fixed binary, so this can be closed!
Somebody beat me to it 😆 Check Homebrew/homebrew-core#91499, that should fix things up.
Sure thing! I’ll give it a spin first thing tomorrow.
– Jeff Byrnes my.pronoun.is/he/him @thejeffbyrnes thejeffbyrnes.com On Dec 16, 2021, 7:23 PM -0500, Juliette @.***>, wrote:
Hmm… just did some testing with the latest PHAR files and am seeing these notices as well… I’ll go do some digging in the PHAR generation to see if there’s something wrong there.