Skip to content

Commit 2aa34aa

Browse files
committed
Fixed bug #594 : Tokenizer issue on closure that returns by reference
1 parent b2050fa commit 2aa34aa

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,7 @@ blah
174174
{
175175
// body
176176
}
177+
178+
$b = function &() {
179+
echo "hello";
180+
};

CodeSniffer/Standards/PEAR/Tests/Functions/FunctionDeclarationUnitTest.inc.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ function blah()
178178
{
179179
// body
180180
}
181+
182+
$b = function &() {
183+
echo "hello";
184+
};

CodeSniffer/Tokenizers/PHP.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,9 @@ public function processAdditional(&$tokens, $eolChar)
854854
// Looking for functions that are actually closures.
855855
if ($tokens[$i]['code'] === T_FUNCTION && isset($tokens[$i]['scope_opener']) === true) {
856856
for ($x = ($i + 1); $x < $numTokens; $x++) {
857-
if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false) {
857+
if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$x]['code']]) === false
858+
&& $tokens[$x]['code'] !== T_BITWISE_AND
859+
) {
858860
break;
859861
}
860862
}

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3232
-- Stops conflict with other projects, like PHP_CodeCoverage
3333
- Added more guard code for syntax errors to various sniffs
3434
- Fixed bug #584 : Squiz.Arrays.ArrayDeclaration sniff gives incorrect NoComma error for multiline string values
35+
- Fixed bug #594 : Tokenizer issue on closure that returns by reference
3536
</notes>
3637
<contents>
3738
<dir name="/">

0 commit comments

Comments
 (0)