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
Forever Free Full-Stack Observability | Grafana Cloud Icon
Forever Free Full-Stack Observability | Grafana Cloud

Our generous forever free tier includes the full platform, including the AI Assistant, for 3 users with 10k metrics, 50GB logs, and 50GB traces.

Built on open standards like Prometheus and OpenTelemetry, Grafana Cloud includes Kubernetes Monitoring, Application Observability, Incident Response, plus the AI-powered Grafana Assistant. Get started with our generous free tier today.
Create free account
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