PHPackages                             loophp/phptree-ast-generator - 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. loophp/phptree-ast-generator

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

loophp/phptree-ast-generator
============================

Generates AST of a PHP script in DOT (Graphviz) or Image (PNG, JPG, SVG) formats.

0.0.2(6y ago)937[1 issues](https://github.com/loophp/phptree-ast-generator/issues)[6 PRs](https://github.com/loophp/phptree-ast-generator/pulls)MITPHPPHP &gt;= 7.1

Since Mar 6Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/loophp/phptree-ast-generator)[ Packagist](https://packagist.org/packages/loophp/phptree-ast-generator)[ GitHub Sponsors](https://github.com/drupol)[ RSS](/packages/loophp-phptree-ast-generator/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (8)Versions (9)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5b0a85df89e0507b3883bfabbf07005f19a322703591aeb238c1541343c53e3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6f7068702f706870747265652d6173742d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/phptree-ast-generator)[![GitHub stars](https://camo.githubusercontent.com/f90480fba20858a088370ddc70b31fa6e345bc2672640aa820c404e2b20771c9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c6f6f7068702f706870747265652d6173742d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/phptree-ast-generator)[![Total Downloads](https://camo.githubusercontent.com/e2337a5b10b7d2b2240f7a52fb538bd0d51497df55c167f2d079cd674f463883/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6f7068702f706870747265652d6173742d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/phptree-ast-generator)[![GitHub Workflow Status](https://camo.githubusercontent.com/b67db048d14cc1684bd073da3db378e1125b89c2b70c1f63224c08d3dfac34c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c6f6f7068702f706870747265652d6173742d67656e657261746f722f436f6e74696e756f7573253230496e746567726174696f6e3f7374796c653d666c61742d737175617265)](https://github.com/loophp/phptree-ast-generator/actions)[![Scrutinizer code quality](https://camo.githubusercontent.com/71e07b916a8df7954816b91ac992101b95595ef736a7163f47b000dd9999b7da/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6c6f6f7068702f706870747265652d6173742d67656e657261746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/loophp/phptree-ast-generator/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/ee895fb91551c33093f959cfc33d1ba3f7a2de939fcdd174cabc46dffdda0212/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6c6f6f7068702f706870747265652d6173742d67656e657261746f722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/loophp/phptree-ast-generator/?branch=master)[![Mutation testing badge](https://camo.githubusercontent.com/5076fcb424acd1009f6c35e1b4729009ee34b4ba769c62668276adc3cbfb9465/68747470733a2f2f62616467652e737472796b65722d6d757461746f722e696f2f6769746875622e636f6d2f6c6f6f7068702f706870747265652d6173742d67656e657261746f722f6d6173746572)](https://stryker-mutator.github.io)[![License](https://camo.githubusercontent.com/e3a0449991436fa2d9d124b542eac0b69bdeec1b115c7bdac99c1aebc4c7a1a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f6f7068702f706870747265652d6173742d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/phptree-ast-generator)[![Donate!](https://camo.githubusercontent.com/f2e288c194c16198351c80fcb396a39afb2ae2ccf89c1549c8dc049901151137/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617970616c2d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://paypal.me/loophp)

PHPTree AST Generator
=====================

[](#phptree-ast-generator)

Description
-----------

[](#description)

An AST generator based on [loophp/phptree](https://packagist.org/packages/loophp/phptree).

[![Demo](resources/src-Command-Generator.png)](resources/src-Command-Generator.png)

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1
- A PHP Parser:
    - [nikic/php-ast](https://github.com/nikic/php-ast)
    - [nikic/php-parser](https://github.com/nikic/php-parser)
    - [microsoft/tolerant-php-parser](https://github.com/microsoft/tolerant-php-parser)

Installation
------------

[](#installation)

`composer require loophp/phptree-ast-generator`

Usage
-----

[](#usage)

Very basic usage

```
./path/to/bin/ast generate /path/to/php/file.php
```

To generate the `dot` script for Graphviz

```
./path/to/bin/ast generate src/Command/Generator.php
```

Use the `-c` option to generate a fancy export, user-friendly and less verbose.

```
./path/to/bin/ast generate -c src/Command/Generator.php
```

To generate an image

```
./path/to/bin/ast generate -c -t image -f png -d graph.png src/Command/Generator.php
```

The generator supports 3 PHP parsers:

- [nikic/php-ast](https://github.com/nikic/php-ast)
- [nikic/php-parser](https://github.com/nikic/php-parser)
- [microsoft/tolerant-php-parser](https://github.com/microsoft/tolerant-php-parser)

Use the `-p` option to change it, default is `nikic`.

```
./path/to/bin/ast generate -p microsoft -t image -d graph.svg src/Command/Generator.php
```

You will find more documentation within the help of the command:

```
./path/to/bin/ast generate -h
```

Contributing
------------

[](#contributing)

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance49

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

2255d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a5b33672e6fed2f03fee680279b6bddb884ca494237764e8c4dbb2c77e8bf05?d=identicon)[drupol](/maintainers/drupol)

---

Top Contributors

[![drupol](https://avatars.githubusercontent.com/u/252042?v=4)](https://github.com/drupol "drupol (12 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (8 commits)")

---

Tags

abstract-syntax-treeastgraphtreetreeastgraphabstract syntax tree

### Embed Badge

![Health badge](/badges/loophp-phptree-ast-generator/health.svg)

```
[![Health](https://phpackages.com/badges/loophp-phptree-ast-generator/health.svg)](https://phpackages.com/packages/loophp-phptree-ast-generator)
```

###  Alternatives

[ajthinking/archetype

Programmatically edit PHP and Laravel files.

2723.4M12](/packages/ajthinking-archetype)[jakubledl/dissect

Lexing and parsing in pure PHP

2244.6M11](/packages/jakubledl-dissect)[palantirnet/drupal-rector

Instant fixes for your Drupal code by using Rector.

1544.2M20](/packages/palantirnet-drupal-rector)[psx/schema

Parse and generate data schema formats

57238.7k18](/packages/psx-schema)[php-soap/wsdl-reader

A WSDL reader in PHP

212.3M9](/packages/php-soap-wsdl-reader)[atanamo/php-codeshift

A PHP code transformation toolkit based on 'PHP-Parser'

32158.4k1](/packages/atanamo-php-codeshift)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
