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

Bug #16836 Notice raised when using semicolon to open case
Submitted: 2009-11-26 10:11 UTC
From: marynicolehicks Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.2.1)
PHP Version: 5.2.5 OS: Windows Vista 32
Roadmaps: (Not assigned)    
Subscription  


 [2009-11-26 10:11 UTC] marynicolehicks (marynicole hicks)
Description: ------------ NOTICE: Undefined index: scope_closer in D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer\Tokenizers\PHP.php on line 459 Test script: --------------- Should be easy to spot in the code. Expected result: ---------------- Expect no notices in logs. Actual result: -------------- 2009-11-26T16:54:15+13:00 ERR (3): NOTICE: Undefined index: scope_closer in D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer\Tokenizers\PHP.php on line 459 #0 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer\Tokenizers\PHP.php(459): My_Log->LogErrorHandler(8, 'Undefined index...', 'D:\My Documents...', 459, Array) #1 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer\File.php(772): PHP_CodeSniffer_Tokenizers_PHP->processAdditional(Array, '??') #2 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer\File.php(512): PHP_CodeSniffer_File::tokenizeString('<?php????/**?? ...', Object(PHP_CodeSniffer_Tokenizers_PHP), '??') #3 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer\File.php(362): PHP_CodeSniffer_File->_parse(NULL) #4 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer.php(784): PHP_CodeSniffer_File->start(NULL) #5 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer.php(690): PHP_CodeSniffer->processFile('D:\My Documents...') #6 D:\My Documents\My Websites\DreamHost\fms\library\Pear\pear\PHP\CodeSniffer.php(341): PHP_CodeSniffer->processFiles('D:\My Documents...', false) #7 D:\My Documents\My Websites\DreamHost\fms\test\CodeSniffer\RunCodeSniffer.php(20): PHP_CodeSniffer->process(Array, 'D:\My Documents...') #8 D:\My Documents\My Websites\DreamHost\fms\test\UnitTests.php(173): include('D:\My Documents...') #9 D:\My Documents\My Websites\DreamHost\fms\test\UnitTests.php(108): UnitTests->runCodeSniffer() #10 D:\My Documents\My Websites\DreamHost\fms\test\UnitTests.php(78): UnitTests->__construct(Object(Zend_Console_Getopt)) #11 {main}

Comments

 [2009-11-26 10:45 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
Errors like this indicate that there is a bit of code PHPCS was unable to tokenise correctly. I never mute errors like this because they mask a bigger problem. To fix them, I need the code you were checking or some sample code that produces the same issue. Are you able to supply some?
 [2009-11-26 14:57 UTC] marynicolehicks (marynicole hicks)
Yes this code here should cause it. I have taken out as much code as I can while still producing the same notice. Annoyingly I could not find where to attach files to comments, so I hope this still causes the problem after posting it. There was an opening PHP tag at the start but this comment box did not allow it. This is up there with some of my worst code, and now I have found it I could tidy up the code, but I still hope it helps fixing that notice. class ErrorController { public function errorAction() { $view = $this->view; $errorMessage = ''; switch ($errorType) { // 404 error -- controller/action not found case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: case '404'; // check for a redirect if ($this->CheckForRedirect()){ return; } // set the http response code to 404 $this->getResponse()->setHttpResponseCode(404); // add the header and info message $fullUrl = $this->_helper->fullurl(); $view->messages[] = '<b>404:</b> The page you requested ('.wordwrap(htmlentities( $fullUrl),75,'<br>',TRUE).') could not be found.'; if (!empty($errorMessage)){ $this->showAdminMessage($view,$errorMessage); } break; // application error; display error page, but don't change // status code default: // add the header and info message $view->messages[] = '<b>500:</b> The page you requested will be under maintenance until tomorrow.'; if (isset($errorMessage)){ My_Log::LogError( $errorMessage, My_Log::ERR ); $this->showAdminMessage($view,$errorMessage); } break; } return $this->_forward('error','home'); } }
 [2009-11-26 15:14 UTC] marynicolehicks (marynicole hicks)
As a little side comment, I have not changed the NOTICE causing piece of code for many months and it seemed to work with version 1.2.0 fine but started causing the problem with 1.2.1
 [2009-11-26 15:22 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Verified
Thanks a lot. Looks like the basic code causing the error is: switch ($errorType) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case '404'; break; }
 [2009-11-30 11:07 UTC] squiz (Greg Sherwood)
This is caused by using a semi-colon to end the CASE statement instead of a colon. PHP_CodeSniffer would have never checked this code correctly although the error may not have been thrown because this is newish code to support more SWITCH structures. Please change the semi-colon to a colon to workaround this issue until it is fixed.
 [2010-01-14 10:52 UTC] squiz (Greg Sherwood)
-Summary: Notice Raised +Summary: Notice raised when using semicolon to open case
 [2010-01-14 10:54 UTC] squiz (Greg Sherwood)
-Status: Verified +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.