ReadonlyFunctionTokenEmulator.php 976 B

12345678910111213141516171819202122232425262728293031
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Lexer\TokenEmulator;
  3. use PhpParser\PhpVersion;
  4. /*
  5. * In PHP 8.1, "readonly(" was special cased in the lexer in order to support functions with
  6. * name readonly. In PHP 8.2, this may conflict with readonly properties having a DNF type. For
  7. * this reason, PHP 8.2 instead treats this as T_READONLY and then handles it specially in the
  8. * parser. This emulator only exists to handle this special case, which is skipped by the
  9. * PHP 8.1 ReadonlyTokenEmulator.
  10. */
  11. class ReadonlyFunctionTokenEmulator extends KeywordEmulator {
  12. public function getKeywordString(): string {
  13. return 'readonly';
  14. }
  15. public function getKeywordToken(): int {
  16. return \T_READONLY;
  17. }
  18. public function getPhpVersion(): PhpVersion {
  19. return PhpVersion::fromComponents(8, 2);
  20. }
  21. public function reverseEmulate(string $code, array $tokens): array {
  22. // Don't bother
  23. return $tokens;
  24. }
  25. }