forked from nikic/PHP-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes us match the PHP 8.2 handling of readonly. Handling of "readonly" functions is moved to the parser to allow distinguishing them from readonly properties with DNF types. We have to uglify the grammar to avoid some shift/reduce conflicts. Thank you WordPress.
- Loading branch information
Showing
8 changed files
with
2,122 additions
and
1,993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PhpParser\Lexer\TokenEmulator; | ||
|
||
use PhpParser\PhpVersion; | ||
|
||
/* | ||
* In PHP 8.1, "readonly(" was special cased in the lexer in order to support functions with | ||
* name readonly. In PHP 8.2, this may conflict with readonly properties having a DNF type. For | ||
* this reason, PHP 8.2 instead treats this as T_READONLY and then handles it specially in the | ||
* parser. This emulator only exists to handle this special case, which is skipped by the | ||
* PHP 8.1 ReadonlyTokenEmulator. | ||
*/ | ||
class ReadonlyFunctionTokenEmulator extends KeywordEmulator { | ||
public function getKeywordString(): string { | ||
return 'readonly'; | ||
} | ||
|
||
public function getKeywordToken(): int { | ||
return \T_READONLY; | ||
} | ||
|
||
public function getPhpVersion(): PhpVersion { | ||
return PhpVersion::fromComponents(8, 2); | ||
} | ||
|
||
public function reverseEmulate(string $code, array $tokens): array { | ||
// Don't bother | ||
return $tokens; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
readonly function | ||
----- | ||
<?php | ||
function readonly() {} | ||
readonly(); | ||
----- | ||
array( | ||
0: Stmt_Function( | ||
attrGroups: array( | ||
) | ||
byRef: false | ||
name: Identifier( | ||
name: readonly | ||
) | ||
params: array( | ||
) | ||
returnType: null | ||
stmts: array( | ||
) | ||
) | ||
1: Stmt_Expression( | ||
expr: Expr_FuncCall( | ||
name: Name( | ||
parts: array( | ||
0: readonly | ||
) | ||
) | ||
args: array( | ||
) | ||
) | ||
) | ||
) |