\PhpParser\ParserMultiple

Summary

Methods
Properties
Constants
__construct()
parse()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
tryParse()
$parsers
N/A

Properties

$parsers

$parsers : array<mixed,\PhpParser\Parser>

Type

array<mixed,\PhpParser\Parser> — List of parsers to try, in order of preference

Methods

__construct()

__construct(array<mixed,\PhpParser\Parser>  $parsers) 

Create a parser which will try multiple parsers in an order of preference.

Parsers will be invoked in the order they're provided to the constructor. If one of the parsers runs without throwing, it's output is returned. Otherwise the exception that the first parser generated is thrown.

Parameters

array<mixed,\PhpParser\Parser> $parsers

parse()

parse(string  $code, \PhpParser\ErrorHandler  $errorHandler = null) : array<mixed,\PhpParser\Node>|null

Parses PHP code into a node tree.

Parameters

string $code

The source code to parse

\PhpParser\ErrorHandler $errorHandler

Error handler to use for lexer/parser errors, defaults to ErrorHandler\Throwing.

Returns

array<mixed,\PhpParser\Node>|null —

Array of statements (or null if the 'throwOnError' option is disabled and the parser was unable to recover from an error).