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

Bug #17243 Alternate Switch Syntax causes endless loop of Notices in SwitchDeclaration
Submitted: 2010-03-18 23:06 UTC
From: ashnazg Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.2.2)
PHP Version: 5.2.4 OS: RHEL4
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 37 + 50 = ?

 
 [2010-03-18 23:06 UTC] ashnazg (Chuck Burgess)
Description: ------------ A switch statement that uses the "alternative" syntax that ends with the "endswitch;" line triggers an endless loop of PHP Notices from the Squiz.ControlsStructures.SwitchDeclaration sniff. Test script: --------------- (Example of alternative switch syntax php.net manual) <?php switch (i): case 0: echo "i equals 0"; break; case 1: echo "i equals 1"; break; default: echo "none of the above"; endswitch; ?> You can remove any particular section of the contents (e.g. the case 0 section, case 1 section, etc) and get the same results. You can even comment out the *entire* guts of it, so that only the switch and endswitch lines remain, with the same result. Expected result: ---------------- Run to completion Actual result: -------------- Endless loop of: PHP Notice: Undefined index: in PHP/CodeSniffer/File.php on line 2224 PHP Stack trace: PHP 1. {main}() phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() phpcs:30 PHP 3. PHP_CodeSniffer->process() PHP/CodeSniffer/CLI.php:429 PHP 4. PHP_CodeSniffer->processFile() PHP/CodeSniffer.php:376 PHP 5. PHP_CodeSniffer->_processFile() PHP/CodeSniffer.php:836 PHP 6. PHP_CodeSniffer_File->start() PHP/CodeSniffer.php:921 PHP 7. Squiz_Sniffs_ControlStructures_SwitchDeclarationSniff->process() PHP/CodeSniffer/File.php:431 PHP 8. PHP_CodeSniffer_File->findPrevious() PHP/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php:206 Notice: Undefined index: in PHP/CodeSniffer/File.php on line 2224 Call Stack: 0.0006 50464 1. {main}() phpcs:0 0.0357 1018772 2. PHP_CodeSniffer_CLI->process() phpcs:30 0.0370 1023908 3. PHP_CodeSniffer->process() PHP/CodeSniffer/CLI.php:429 0.2301 4471652 4. PHP_CodeSniffer->processFile() PHP/CodeSniffer.php:376 0.2303 4471732 5. PHP_CodeSniffer->_processFile() PHP/CodeSniffer.php:836 0.2307 4472580 6. PHP_CodeSniffer_File->start() PHP/CodeSniffer.php:921 0.2898 4595384 7. Squiz_Sniffs_ControlStructures_SwitchDeclarationSniff->process() PHP/CodeSniffer/File.php:431 0.3526 4597796 8. PHP_CodeSniffer_File->findPrevious() PHP/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php:206

Comments

 [2010-03-19 05:17 UTC] squiz (Greg Sherwood)
-Assigned To: +Assigned To: squiz
I don't support the alternate syntax because it is too tricky. There are no scope openers (i.e, no open curly brace) so it is hard to assign a token to be the opener without breaking everything. Can be done with enough effort, but not something I am looking to do. I will fix the sniff so that it knows to ignore these though and wont go into an infinite loop trying to find the start of the SWITCH.
 [2010-03-19 05:19 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.