Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,11 @@ protected function tokenize($string)
) {
$preserveKeyword = false;

// `new class` should be preserved
if ($token[0] === T_CLASS && $finalTokens[$lastNotEmptyToken]['code'] === T_NEW) {
// `new class`, and `new static` should be preserved.
if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW
&& ($token[0] === T_CLASS
|| $token[0] === T_STATIC)
) {
$preserveKeyword = true;
}

Expand Down Expand Up @@ -1968,16 +1971,24 @@ function return types. We want to keep the parenthesis map clean,
&& $token[0] === T_STRING
&& isset($this->tstringContexts[$finalTokens[$lastNotEmptyToken]['code']]) === true
) {
// Special case for syntax like: return new self
// where self should not be a string.
// Special case for syntax like: return new self/new parent
// where self/parent should not be a string.
$tokenContentLower = strtolower($token[1]);
if ($finalTokens[$lastNotEmptyToken]['code'] === T_NEW
&& strtolower($token[1]) === 'self'
&& ($tokenContentLower === 'self' || $tokenContentLower === 'parent')
) {
$finalTokens[$newStackPtr] = [
'content' => $token[1],
'code' => T_SELF,
'type' => 'T_SELF',
];
if ($tokenContentLower === 'self') {
$finalTokens[$newStackPtr]['code'] = T_SELF;
$finalTokens[$newStackPtr]['type'] = 'T_SELF';
}

if ($tokenContentLower === 'parent') {
$finalTokens[$newStackPtr]['code'] = T_PARENT;
$finalTokens[$newStackPtr]['type'] = 'T_PARENT';
}
} else {
$finalTokens[$newStackPtr] = [
'content' => $token[1],
Expand Down
Loading