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

Bug #18951 weird behaviour with closures and multi-line use () params
Submitted: 2011-10-31 19:33 UTC
From: domnikl Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: 5.3.6 OS: Ubuntu 11.10
Roadmaps: (Not assigned)    
Subscription  


 [2011-10-31 19:33 UTC] domnikl (Dominik Liebler)
Description: ------------ I have closures in my project which take a long list of parameters and import them from the parent scope via use(). There's a weird bug when I put all the params for use() in one parameter per row, formatting them as I would expect was correct (I use the built- in Zend standard but tested it with PEAR too). The errors say for each line before the anonymous function declaration: "Multi-line function call not intented correctly" Tested also with 1.3.0RC1 and 2 That just generated 257 check style errors on my CI and took me a while to figure out ;-) Test script: --------------- <?php function foobar(Closure $foo) { $foo(); } $foo = 'f'; $bar = 'o'; $baz = 'o'; // Won't work foobar( function ( $foo, $bar, $baz ) use ( $foo, $bar, $baz ) { echo $foo . $bar. $baz; } ); // works correctly foobar( function ( $foo, $bar, $baz ) use ( $foo, $bar, $baz ) { echo $foo . $bar. $baz; } ); Expected result: ---------------- both cases return no error Actual result: -------------- -------------------------------------------------------------------------------- FOUND 10 ERROR(S) AND 1 WARNING(S) AFFECTING 10 LINE(S) -------------------------------------------------------------------------------- 2 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 1 3 | WARNING | Consider putting global function "foobar" in a static class 3 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 0 7 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 1 8 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 0 9 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 0 10 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 0 11 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 1 12 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 0 13 | ERROR | Multi-line function call not indented correctly; expected 4 | | spaces but found 0 35 | ERROR | Opening brace should be on the line after the declaration; | | found 1 blank line(s) --------------------------------------------------------------------------------

Comments

 [2011-11-01 05:57 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Verified -Assigned To: +Assigned To: squiz
Also getting these errors when run: PHP Notice: Undefined index: scope_opener in /Users/gsherwood/PHP_CodeSniffer/trunk/CodeSniffer/Tokenizers/PHP.php on line 460 PHP Notice: Undefined index: scope_closer in /Users/gsherwood/PHP_CodeSniffer/trunk/CodeSniffer/Tokenizers/PHP.php on line 460 PHP Notice: Undefined index: scope_closer in /Users/gsherwood/PHP_CodeSniffer/trunk/CodeSniffer/Standards/PEAR/Sniffs/Functi ons/FunctionCallSignatureSniff.php on line 230 PHP Notice: Undefined index: in /Users/gsherwood/PHP_CodeSniffer/trunk/CodeSniffer/Standards/PEAR/Sniffs/Functi ons/FunctionCallSignatureSniff.php on line 231 So looks like a tokenizing issue.
 [2011-11-01 08:51 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. Was actually caused by the tokenzier stopping after not finding the opening brace after 3 lines. It only does this for control structures that don't require braces, but functions do require braces. They just weren't marked as being required in the core.