This is a PHP 5.2 to PHP 8.0 parser written in PHP. Its purpose is to simplify static code analysis and manipulation. A parser is useful for static analysis, manipulation of code and basically any other application dealing with code programmatically. A parser constructs an Abstract Syntax Tree (AST) of the code and thus allows dealing with it in an abstract and robust way. As the parser is based on the tokens returned by token_get_all (which is only able to lex the PHP version it runs on), additionally a wrapper for emulating tokens from newer versions is provided. This allows to parse PHP 7.4 source code running on PHP 7.0, for example. This emulation is somewhat hacky and not perfect, but it should work well on any sane code. Support for pretty printing, which is the act of converting an AST into PHP code. Please note that "pretty printing" does not imply that the output is especially pretty.

Features

  • Parsing PHP 5, PHP 7, and PHP 8 code into an abstract syntax tree (AST)
  • Dumping the AST in human-readable form
  • Converting an AST back to PHP code
  • Infrastructure to traverse and modify ASTs
  • Resolution of namespaced names
  • Evaluation of constant expressions
  • Builders to simplify AST construction for code generation
  • Converting an AST into JSON and back

Project Samples

Project Activity

See All Activity >

License

BSD License

Follow PHP Parser

PHP Parser Web Site

Other Useful Business Software
Powering the best of the internet | Fastly Icon
Powering the best of the internet | Fastly

Fastly's edge cloud platform delivers faster, safer, and more scalable sites and apps to customers.

Ensure your websites, applications and services can effortlessly handle the demands of your users with Fastly. Fastly’s portfolio is designed to be highly performant, personalized and secure while seamlessly scaling to support your growth.
Try for free
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of PHP Parser!

Additional Project Details

Programming Language

PHP

Related Categories

PHP Source Code Analysis Tool, PHP Static Code Analysis Tool

Registered

2021-04-09