Skip to content

Commit 577b2b8

Browse files
committed
Tokenizer/PHP: bug fix for match within ternary
This fixes the mis-identification of a `T_DEFAULT` token within a (not yet retokenized) `match` structure as a `switch` `default` token, which resulted in a `T_COLON` token incorrectly not being retokenized to `T_INLINE_ELSE`. As a complete test file for ternary tokenization does not exist (yet), I've added a unit test to the `Squiz.Objects.ObjectInstantiation` sniff. The code in the test would cause a false positive for the `ObjectInstantiation` sniff without this fix. Fixes 3789
1 parent ed8e00d commit 577b2b8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Standards/Squiz/Tests/Objects/ObjectInstantiationUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ function nonAssignmentTernary() {
4141
}
4242
}
4343

44+
// Test for tokenizer issue #3789.
45+
$a = $b !== null
46+
? match ($c) {
47+
default => 5,
48+
}
49+
: new Foo;
50+
4451
// Intentional parse error. This must be the last test in the file.
4552
function new
4653
?>

src/Tokenizers/PHP.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,11 +2249,12 @@ function return types. We want to keep the parenthesis map clean,
22492249

22502250
if (is_array($tokens[$i]) === false
22512251
&& ($tokens[$i] === ';'
2252-
|| $tokens[$i] === '{')
2252+
|| $tokens[$i] === '{'
2253+
|| $tokens[$i] === '}')
22532254
) {
22542255
break;
22552256
}
2256-
}
2257+
}//end for
22572258
}//end if
22582259

22592260
if ($isInlineIf === true) {

0 commit comments

Comments
 (0)