About this project

PHP-Parser is a Composer-installable PHP library intended to simplify static code analysis and code manipulation. It parses PHP 7 and PHP 8 source files into an abstract syntax tree, including accurate location information, and can recover from syntax errors to produce a partial AST. The library provides tools for dumping ASTs in a human-readable form, traversing nodes with visitors, modifying nodes, resolving namespaced names, evaluating constant expressions, and constructing ASTs through builder objects. ASTs can also be converted to JSON and restored from JSON. A pretty printer converts ASTs back into PHP code and can preserve formatting for partially changed trees. Version 5.x runs on PHP 7.4 or newer, parses PHP 7.0 through PHP 8.4, and has limited PHP 5.x parsing support. Version 4.x remains supported for PHP 7.0 or newer and parses PHP 5.2 through PHP 8.3. The documentation covers basic usage, AST walking, name resolution, pretty printing, builders, lexer tokens and positions, error recovery, constant expression evaluation, JSON representation, and performance considerations.