Skip to content

Commit

Permalink
Tokenizer/PHP: bug fix in improved context sensitive keyword support [1]
Browse files Browse the repository at this point in the history
As reported in 3607, the `eval` keyword was not included in the list of context sensitive keyword. This is a regression compared to PHPCS 3.6.2.

Fixed now, including unit tests.

Fixes 3607
  • Loading branch information
jrfnl committed Jun 12, 2022
1 parent 5e27199 commit 854aba7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Util/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ final class Tokens
T_ENDSWITCH => T_ENDSWITCH,
T_ENDWHILE => T_ENDWHILE,
T_ENUM => T_ENUM,
T_EVAL => T_EVAL,
T_EXIT => T_EXIT,
T_EXTENDS => T_EXTENDS,
T_FINAL => T_FINAL,
Expand Down
5 changes: 5 additions & 0 deletions tests/Core/Tokenizer/ContextSensitiveKeywordsTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ContextSensitiveKeywords
const /* testEndSwitch */ ENDSWITCH = 'ENDSWITCH';
const /* testEndWhile */ ENDWHILE = 'ENDWHILE';
const /* testEnum */ ENUM = 'ENUM';
const /* testEval */ EVAL = 'EVAL';
const /* testExit */ EXIT = 'EXIT';
const /* testExtends */ EXTENDS = 'EXTENDS';
const /* testFinal */ FINAL = 'FINAL';
Expand Down Expand Up @@ -165,6 +166,8 @@ echo $foo;
print $foo;
/* testDieIsKeyword */
die($foo);
/* testEvalIsKeyword */
eval('<?php echo 5;');
/* testExitIsKeyword */
exit;

Expand Down Expand Up @@ -212,3 +215,5 @@ $instantiated3 = new /* testClassInstantiationStaticIsKeyword */ static($param);

class Foo extends /* testNamespaceInNameIsKeyword */ namespace\Exception
{}

function /* testKeywordAfterFunctionShouldBeString */ eval() {}
7 changes: 7 additions & 0 deletions tests/Core/Tokenizer/ContextSensitiveKeywordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function dataStrings()
['/* testEndSwitch */'],
['/* testEndWhile */'],
['/* testEnum */'],
['/* testEval */'],
['/* testExit */'],
['/* testExtends */'],
['/* testFinal */'],
Expand Down Expand Up @@ -121,6 +122,8 @@ public function dataStrings()
['/* testNamespaceNameIsString1 */'],
['/* testNamespaceNameIsString2 */'],
['/* testNamespaceNameIsString3 */'],

['/* testKeywordAfterFunctionShouldBeString */'],
];

}//end dataStrings()
Expand Down Expand Up @@ -376,6 +379,10 @@ public function dataKeywords()
'/* testDieIsKeyword */',
'T_EXIT',
],
[
'/* testEvalIsKeyword */',
'T_EVAL',
],
[
'/* testExitIsKeyword */',
'T_EXIT',
Expand Down

0 comments on commit 854aba7

Please sign in to comment.