=')) { return false; } return strpos($code, '??=') !== false; } public function emulate(string $code, array $tokens): array { // We need to manually iterate and manage a count because we'll change // the tokens array on the way for ($i = 0, $c = count($tokens); $i < $c; ++$i) { if (isset($tokens[$i + 1])) { $token = $tokens[$i]; if ($token->id === \T_COALESCE && $tokens[$i + 1]->value === '=') { array_splice($tokens, $i, 2, [ new Token(Emulative::T_COALESCE_EQUAL, '??=', $token->line, $token->filePos), ]); $c--; continue; } } } return $tokens; } }