Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.4.2

Bug #19137 undefined index notice on closure inside if statement
Submitted: 2011-12-15 12:19 UTC
From: ebernhardson Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.2)
PHP Version: 5.3.6 OS: Ubuntu oneiric
Roadmaps: (Not assigned)    
Subscription  


 [2011-12-15 12:19 UTC] ebernhardson (Erik Bernhardson)
Description: ------------ When running the provided test script through PHP_CodeSniffer a couple of notices are generated in the Tokenizer Test script: --------------- <?php if (array_reduce($x, function($a, $b) { return $a ?: $b === 1; }, false)) { echo "foo"; } Expected result: ---------------- When the scipt above is run through phpcs i expect no notices to occur Actual result: -------------- PHP Notice: Undefined index: scope_opener in /usr/share/php/PHP/CodeSniffer/Tokenizers/PHP.php on line 482 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:37 PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:551 PHP 4. PHP_CodeSniffer->processFile() /usr/share/php/PHP/CodeSniffer.php:476 PHP 5. PHP_CodeSniffer->_processFile() /usr/share/php/PHP/CodeSniffer.php:1141 PHP 6. PHP_CodeSniffer_File->start() /usr/share/php/PHP/CodeSniffer.php:1261 PHP 7. PHP_CodeSniffer_File->_parse() /usr/share/php/PHP/CodeSniffer/File.php:382 PHP 8. PHP_CodeSniffer_File::tokenizeString() /usr/share/php/PHP/CodeSniffer/File.php:586 PHP 9. PHP_CodeSniffer_Tokenizers_PHP- >processAdditional() /usr/share/php/PHP/CodeSniffer/File.php:969 PHP Notice: Undefined index: scope_closer in /usr/share/php/PHP/CodeSniffer/Tokenizers/PHP.php on line 482 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:37 PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:551 PHP 4. PHP_CodeSniffer->processFile() /usr/share/php/PHP/CodeSniffer.php:476 PHP 5. PHP_CodeSniffer->_processFile() /usr/share/php/PHP/CodeSniffer.php:1141 PHP 6. PHP_CodeSniffer_File->start() /usr/share/php/PHP/CodeSniffer.php:1261 PHP 7. PHP_CodeSniffer_File->_parse() /usr/share/php/PHP/CodeSniffer/File.php:382 PHP 8. PHP_CodeSniffer_File::tokenizeString() /usr/share/php/PHP/CodeSniffer/File.php:586 PHP 9. PHP_CodeSniffer_Tokenizers_PHP- >processAdditional() /usr/share/php/PHP/CodeSniffer/File.php:969

Comments

 [2011-12-16 09:10 UTC] squiz (Greg Sherwood)
-Assigned To: +Assigned To: squiz
The notices are a consequence of token scope parsing not occurring during the parenthesis of the IF statement, as seen in the verbose output: *** START SCOPE MAP *** Start scope map at 1: T_IF => if Process token 2 []: T_WHITESPACE => Process token 3 []: T_OPEN_PARENTHESIS => ( * skipping parenthesis * Process token 39 []: T_WHITESPACE => Process token 40 []: T_OPEN_CURLY_BRACKET => { => Found scope opener for 1 (T_IF) Process token 41 [opener:40;]: T_WHITESPACE => \n Process token 42 [opener:40;]: T_WHITESPACE => Process token 43 [opener:40;]: T_ECHO => echo Process token 44 [opener:40;]: T_WHITESPACE => Process token 45 [opener:40;]: T_CONSTANT_ENCAPSED_STRING => "foo" Process token 46 [opener:40;]: T_SEMICOLON => ; Process token 47 [opener:40;]: T_WHITESPACE => \n Process token 48 [opener:40;]: T_CLOSE_CURLY_BRACKET => } => Found scope closer for 1 (T_IF) *** END SCOPE MAP *** Removing the notices is easy. Parsing inside the brackets will potentially break a lot of things and needs to be fixed carefully.
 [2012-08-17 07:40 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
The notices were fixed long ago and I don't remember what I was going to try and fix in the tokenizer. No need to keep this open any longer.