diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 192fbc3de9..3246f8654e 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -2217,6 +2217,8 @@ protected function tokenize($string) if ($tokenIsArray === true && $token[0] === T_STRING && strtolower($token[1]) === 'fn' + && isset(static::T_STRING_CONTEXTS[$finalTokens[$lastNotEmptyToken]['code']]) === false + && $finalTokens[$lastNotEmptyToken]['content'] !== '&' ) { // Modify the original token stack so that // future checks (like looking for T_NULLABLE) can diff --git a/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.inc b/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.inc index 9cdc341797..853e94cedc 100644 --- a/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.inc +++ b/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.inc @@ -60,8 +60,14 @@ function name($a, $b/* testFunctionParenthesesCloser */) {} function &returnByRef ($a, $b/* testFunctionParenthesesCloserReturnByRef */) {} class ReservedKeyword { - /* testFunctionParenthesesOwnerKeywordName */ - public function match($a, $b/* testFunctionParenthesesCloserKeywordName */) {} + /* testFunctionParenthesesOwnerKeywordNameMatch */ + public function match($a, $b/* testFunctionParenthesesCloserKeywordNameMatch */) {} + + /* testFunctionParenthesesOwnerKeywordNameFn */ + public function fn($a, $b/* testFunctionParenthesesCloserKeywordNameFn */) {} + + /* testFunctionParenthesesOwnerKeywordNameFnReturnByRef */ + public function &fn($a, $b/* testFunctionParenthesesCloserKeywordNameFnReturnByRef */) {} } /* testClosureParenthesesOwner */ diff --git a/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.php b/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.php index 39c91fa879..f4068b5047 100644 --- a/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.php +++ b/tests/Core/Tokenizers/Tokenizer/CreateTokenMapParenthesesTest.php @@ -139,8 +139,16 @@ public static function dataParenthesesWithOwner() 'testMarker' => '/* testFunctionParenthesesOwnerReturnByRef */', 'tokenCode' => T_FUNCTION, ], - 'function declaration, keyword as function name' => [ - 'testMarker' => '/* testFunctionParenthesesOwnerKeywordName */', + 'function declaration, "match" as function name' => [ + 'testMarker' => '/* testFunctionParenthesesOwnerKeywordNameMatch */', + 'tokenCode' => T_FUNCTION, + ], + 'function declaration, "fn" as function name' => [ + 'testMarker' => '/* testFunctionParenthesesOwnerKeywordNameFn */', + 'tokenCode' => T_FUNCTION, + ], + 'function declaration, "&fn" as function name' => [ + 'testMarker' => '/* testFunctionParenthesesOwnerKeywordNameFnReturnByRef */', 'tokenCode' => T_FUNCTION, ], 'closure declaration' => [ @@ -276,7 +284,7 @@ public static function dataParenthesesWithoutOwner() /** - * Test parentheses owner tokens when used without parentheses (where possible) do *not* the "parenthesis_*" token indexes set. + * Test parentheses owner tokens when used without parentheses (where possible) do *not* have the "parenthesis_*" token indexes set. * * @param string $testMarker The comment prefacing the target token. * @param int|string $tokenCode The token code to look for.