PHPackages                             lyhiving/php-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. lyhiving/php-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

lyhiving/php-parser
===================

A PHP parser written in PHP

v4.11.0(4y ago)014BSD-3-ClausePHPPHP &gt;=7.0

Since Jan 5Pushed 4y agoCompare

[ Source](https://github.com/lyhiving/php-parser)[ Packagist](https://packagist.org/packages/lyhiving/php-parser)[ RSS](/packages/lyhiving-php-parser/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (79)Used By (0)

PHP Parser
==========

[](#php-parser)

[![Coverage Status](https://camo.githubusercontent.com/5c74b7d687daeb9de09aaf1d94fbaf57286d372dd1aed827759f09ce44082914/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e696b69632f5048502d5061727365722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/nikic/PHP-Parser?branch=master)

This is a PHP 5.2 to PHP 8.0 parser written in PHP. Its purpose is to simplify static code analysis and manipulation.

[**Documentation for version 4.x**](https://github.com/nikic/PHP-Parser/tree/master/doc) (stable; for running on PHP &gt;= 7.0; for parsing PHP 5.2 to PHP 8.0).

[Documentation for version 3.x](https://github.com/nikic/PHP-Parser/tree/3.x/doc) (unsupported; for running on PHP &gt;= 5.5; for parsing PHP 5.2 to PHP 7.2).

Features
--------

[](#features)

The main features provided by this library are:

- Parsing PHP 5, PHP 7, and PHP 8 code into an abstract syntax tree (AST).
    - Invalid code can be parsed into a partial AST.
    - The AST contains accurate location information.
- Dumping the AST in human-readable form.
- Converting an AST back to PHP code.
    - Experimental: Formatting can be preserved for partially changed ASTs.
- 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.

Quick Start
-----------

[](#quick-start)

Install the library using [composer](https://getcomposer.org):

```
php composer.phar require nikic/php-parser

```

Parse some PHP code into an AST and dump the result in human-readable form:

```
