Skip to content

Commit 854aba7

Browse files
committed
Tokenizer/PHP: bug fix in improved context sensitive keyword support [1]
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
1 parent 5e27199 commit 854aba7

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/Util/Tokens.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ final class Tokens
694694
T_ENDSWITCH => T_ENDSWITCH,
695695
T_ENDWHILE => T_ENDWHILE,
696696
T_ENUM => T_ENUM,
697+
T_EVAL => T_EVAL,
697698
T_EXIT => T_EXIT,
698699
T_EXTENDS => T_EXTENDS,
699700
T_FINAL => T_FINAL,

tests/Core/Tokenizer/ContextSensitiveKeywordsTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ContextSensitiveKeywords
2929
const /* testEndSwitch */ ENDSWITCH = 'ENDSWITCH';
3030
const /* testEndWhile */ ENDWHILE = 'ENDWHILE';
3131
const /* testEnum */ ENUM = 'ENUM';
32+
const /* testEval */ EVAL = 'EVAL';
3233
const /* testExit */ EXIT = 'EXIT';
3334
const /* testExtends */ EXTENDS = 'EXTENDS';
3435
const /* testFinal */ FINAL = 'FINAL';
@@ -165,6 +166,8 @@ echo $foo;
165166
print $foo;
166167
/* testDieIsKeyword */
167168
die($foo);
169+
/* testEvalIsKeyword */
170+
eval('<?php echo 5;');
168171
/* testExitIsKeyword */
169172
exit;
170173

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

213216
class Foo extends /* testNamespaceInNameIsKeyword */ namespace\Exception
214217
{}
218+
219+
function /* testKeywordAfterFunctionShouldBeString */ eval() {}

tests/Core/Tokenizer/ContextSensitiveKeywordsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function dataStrings()
7272
['/* testEndSwitch */'],
7373
['/* testEndWhile */'],
7474
['/* testEnum */'],
75+
['/* testEval */'],
7576
['/* testExit */'],
7677
['/* testExtends */'],
7778
['/* testFinal */'],
@@ -121,6 +122,8 @@ public function dataStrings()
121122
['/* testNamespaceNameIsString1 */'],
122123
['/* testNamespaceNameIsString2 */'],
123124
['/* testNamespaceNameIsString3 */'],
125+
126+
['/* testKeywordAfterFunctionShouldBeString */'],
124127
];
125128

126129
}//end dataStrings()
@@ -376,6 +379,10 @@ public function dataKeywords()
376379
'/* testDieIsKeyword */',
377380
'T_EXIT',
378381
],
382+
[
383+
'/* testEvalIsKeyword */',
384+
'T_EVAL',
385+
],
379386
[
380387
'/* testExitIsKeyword */',
381388
'T_EXIT',

0 commit comments

Comments
 (0)