FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19137&edit=1

ID: 19137
Updated by: gsherwood@squiz.net
Reported By: bernhardsonerik at gmail dot com
Summary: undefined index notice on closure inside if statement
Status: Open
Type: Bug
Package: PHP_CodeSniffer
Operating System: Ubuntu oneiric
Package Version: 1.3.2
PHP Version: 5.3.6
-Assigned To:
+Assigned To: squiz
Roadmap Versions:
New Comment:

-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.


Previous Comments:
------------------------------------------------------------------------

[2011-12-15 07:19:36] ebernhardson

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

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedDec 16, '11 at 3:10a
activeDec 16, '11 at 3:10a
posts1
users1
websitepear.php.net

1 user in discussion

Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase