A next-generation PHP documentation parser with an abstract syntax tree, supporting intersection types, generics, and format-preserving printing.
phpstan/phpdoc-parser is a library that parses PHPDoc comments into an Abstract Syntax Tree (AST), enabling programmatic analysis and manipulation of PHP documentation. It serves as the foundation for static analysis tools like PHPStan, providing a robust and extensible way to work with modern PHPDoc syntax.
Developers building static analysis tools, IDE plugins, documentation generators, or automated refactoring tools for PHP codebases that need to parse and manipulate PHPDoc comments programmatically.
Developers choose this parser for its comprehensive support of modern PHPDoc syntax (including union/intersection types, generics, conditional types), its format-preserving printer for automated refactoring, and its proven reliability as the foundation for PHPStan.
Next-gen phpDoc parser with support for intersection types and generics
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 advanced PHPDoc features like union/intersection types, generics with variance, conditional types, and constant expressions, as detailed in the README's type syntax section.
Parses PHPDocs into a structured Abstract Syntax Tree, enabling precise inspection and transformation through a visitor-based traversal system inspired by nikic/PHP-Parser.
Includes a printer that can modify the AST and reprint it while maintaining original formatting, useful for automated refactoring tools as demonstrated in the README examples.
Provides dedicated AST nodes for parsing Doctrine annotations alongside standard PHPDoc tags, enhancing compatibility for mixed documentation formats.
Initialization requires configuring multiple components (Lexer, ParserConfig, TypeParser, etc.), which can be cumbersome and error-prone for quick integrations or simple use cases.
The library's extensive feature set introduces overhead that might be unnecessary for projects only needing basic PHPDoc parsing, potentially affecting performance in lightweight environments.
Full feature lists and detailed guides are documented on PHPStan's external site, requiring developers to cross-reference and potentially missing integrated, standalone examples.