Describe the bug
The bug appears to be that $data is a string, not an array.
Code sample
<?php
function test()
{
// test
$a = 'test';
$variable = [];
foreach ($variable as $key => $value) {
# code...
$value = 'test';
}
}
add_action('wp_head', 'test');
Custom ruleset
No custom ruleset, besides using WordPress-Extra Coding Standards.
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php with the code sample above...
- Run
phpcs --standard=WordPress-Extra /Users/michael.sumner/Desktop/test.php (change to your path to test.php)
- See error message displayed
mic@Mics-MacBook-Pro ~ % phpcs --standard=WordPress-Extra /Users/michael.sumner/Desktop/test.php
PHP Fatal error: Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, string given in /.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php:1050
Stack trace:
#0 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(1050): vsprintf('Expected exactl...', '\n')
#1 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(670): PHP_CodeSniffer\Files\File->addMessage(true, 'Expected exactl...', 3, 1, 'ExtraSpaceAfter...', '\n', 5, true)
#2 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(778): PHP_CodeSniffer\Files\File->addError('Expected exactl...', 2, 'ExtraSpaceAfter...', '\n', 0, true)
#3 /Users/michael.sumner/.composer/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php(395): PHP_CodeSniffer\Files\File->addFixableError('Expected exactl...', 2, 'ExtraSpaceAfter...', '\n')
#4 /Users/michael.sumner/.composer/vendor/wp-coding-standards/wpcs/WordPress/Sniff.php(910): WordPressCS\WordPress\Sniffs\WhiteSpace\ControlStructureSpacingSniff->process_token(2)
#5 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(496): WordPressCS\WordPress\Sniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 2)
#6 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(91): PHP_CodeSniffer\Files\File->process()
#7 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(630): PHP_CodeSniffer\Files\LocalFile->process()
#8 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))
#9 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
#10 /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#11 {main}
thrown in /Users/michael.sumner/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 1050
Expected behavior
That the FatalError message will not be displayed.
Versions (please complete the following information):
- OS: MacOS 11.1
- PHP: 8.0.1
- PHPCS: master
- Standard: WordPress-Extra
Additional context
N/A
Describe the bug
The bug appears to be that $data is a string, not an array.
Code sample
Custom ruleset
No custom ruleset, besides using WordPress-Extra Coding Standards.
To reproduce
Steps to reproduce the behavior:
test.phpwith the code sample above...phpcs --standard=WordPress-Extra /Users/michael.sumner/Desktop/test.php(change to your path to test.php)Expected behavior
That the FatalError message will not be displayed.
Versions (please complete the following information):
Additional context
N/A