Documentation

Emulative extends Lexer
in package

Table of Contents

Properties

$emulators  : array<int, TokenEmulator>
$hostPhpVersion  : PhpVersion
$patches  : array<string|int, array{: int, : string, : string}>
$targetPhpVersion  : PhpVersion

Methods

__construct()  : mixed
tokenize()  : array<string|int, Token>
Tokenize the provided source code.
postprocessTokens()  : void
fixupErrors()  : void
Fixup line and position information in errors.
fixupTokens()  : array<int, Token>
handleInvalidCharacter()  : void
isForwardEmulationNeeded()  : bool
isReverseEmulationNeeded()  : bool
isUnterminatedComment()  : bool
sortPatches()  : void

Properties

$emulators

private array<int, TokenEmulator> $emulators = []

$patches

private array<string|int, array{: int, : string, : string}> $patches = []

Patches used to reverse changes introduced in the code

Methods

__construct()

public __construct([PhpVersion|null $phpVersion = null ]) : mixed
Parameters
$phpVersion : PhpVersion|null = null

PHP version to emulate. Defaults to newest supported.

tokenize()

Tokenize the provided source code.

public tokenize(string $code[, ErrorHandler|null $errorHandler = null ]) : array<string|int, Token>

The token array is in the same format as provided by the PhpToken::tokenize() method in PHP 8.0. The tokens are instances of PhpParser\Token, to abstract over a polyfill implementation in earlier PHP version.

The token array is terminated by a sentinel token with token ID 0. The token array does not discard any tokens (i.e. whitespace and comments are included). The token position attributes are against this token array.

Parameters
$code : string

The source code to tokenize.

$errorHandler : ErrorHandler|null = null

Error handler to use for lexing errors. Defaults to ErrorHandler\Throwing.

Return values
array<string|int, Token>

Tokens

fixupErrors()

Fixup line and position information in errors.

private fixupErrors(array<string|int, Error$errors) : void
Parameters
$errors : array<string|int, Error>

fixupTokens()

private fixupTokens(array<int, Token$tokens) : array<int, Token>
Parameters
$tokens : array<int, Token>
Return values
array<int, Token>

isForwardEmulationNeeded()

private isForwardEmulationNeeded(PhpVersion $emulatorPhpVersion) : bool
Parameters
$emulatorPhpVersion : PhpVersion
Return values
bool

isReverseEmulationNeeded()

private isReverseEmulationNeeded(PhpVersion $emulatorPhpVersion) : bool
Parameters
$emulatorPhpVersion : PhpVersion
Return values
bool

isUnterminatedComment()

private isUnterminatedComment(Token $token) : bool
Parameters
$token : Token
Return values
bool

        
On this page

Search results