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

Bug #18973 phpcs is looking for variables in a nowdoc
Submitted: 2011-11-08 22:33 UTC
From: bkendig Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version SVN)
PHP Version: 5.3.8 OS: Mac OS X 10.6.8
Roadmaps: (Not assigned)    
Subscription  


 [2011-11-08 22:33 UTC] bkendig (Brian Kendig)
Description: ------------ A quoted value in a nowdoc, like "$456", gives an error: Variable "456" is not in valid camel caps format According to "http://php.net/manual/en/language.types.string.php", text in nowdocs is not parsed. phpcs should not be flagging an error here. Test script: --------------- $ cat foo.php <?php $foo = <<<'BAR' $123 "$456" BAR; Expected result: ---------------- Nothing. Actual result: -------------- $ php PHP_CodeSniffer/scripts/phpcs -- foo.php -- standard=Zend FILE: /Users/brkendig/foo.php ------------------------------------------------------------------------ -------- FOUND 1 ERROR(S) AFFECTING 1 LINE(S) ------------------------------------------------------------------------ -------- 4 | ERROR | Variable "456" is not in valid camel caps format ------------------------------------------------------------------------ --------

Comments

 [2011-11-09 00:18 UTC] bkendig (Brian Kendig)
The same error also occurs in heredocs. php won't recognize $456 as a valid variable name, so phpcs shouldn't be catching it either.
 [2011-11-11 07:27 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
Fix committed. PHP tokenizes heredocs and nowdocs using the same tokens, but that confuses some sniffs. PHP_CodeSniffer now detects nowdocs and uses it's own token types. So look for T_START_NOWDOC instead of T_START_HEREDOC if you want to detect nowdocs specifically.