A PHP parser written in PHP for static code analysis and manipulation via an abstract syntax tree (AST).
PHP-Parser is a library written in PHP that parses PHP source code into an abstract syntax tree (AST). It enables developers to programmatically analyze, traverse, and manipulate PHP code for tasks like static analysis, refactoring, and custom tooling. The tool supports modern PHP versions and handles invalid code gracefully with partial ASTs.
PHP developers building static analysis tools, code refactoring utilities, linters, or any application requiring programmatic inspection or modification of PHP source code.
Developers choose PHP-Parser for its accuracy, comprehensive feature set, and active maintenance. It provides a reliable foundation for code manipulation with support for modern PHP versions, name resolution, and AST-to-code conversion, all within a pure PHP environment.
A PHP parser written in PHP
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports PHP 7.0 to 8.4 with precise location information and can parse invalid code into partial ASTs, as highlighted in the features list.
Provides traversal infrastructure and node visitors for easy code modifications, demonstrated in the quick start example for stripping function bodies.
Converts ASTs back to PHP code while maintaining original formatting for unmodified parts, enabling incremental changes without style disruption.
Resolves namespaced names within the AST, essential for accurate static analysis without runtime execution, as documented in the components.
Requires deep understanding of AST structures and node types, making it inaccessible for developers needing simple, quick solutions.
Parsing and traversing large codebases can be resource-intensive, with documentation advising optimizations like disabling Xdebug.
Maintains multiple active branches (e.g., 4.x and 5.x) with differing PHP version support, which can confuse users about compatibility.