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