PHPackages                             tysonandre/php-parser-to-php-ast - 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. tysonandre/php-parser-to-php-ast

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

tysonandre/php-parser-to-php-ast
================================

A pure PHP substitute for nikic/php-ast, using nikic/php-parser. Can also be used to generate php-ast trees, even for files with some types of syntax errors.

0.2.1(6y ago)1242[3 issues](https://github.com/TysonAndre/php-parser-to-php-ast/issues)[1 PRs](https://github.com/TysonAndre/php-parser-to-php-ast/pulls)MITPHPPHP &gt;=7.1CI failing

Since Sep 1Pushed 6y ago3 watchersCompare

[ Source](https://github.com/TysonAndre/php-parser-to-php-ast)[ Packagist](https://packagist.org/packages/tysonandre/php-parser-to-php-ast)[ RSS](/packages/tysonandre-php-parser-to-php-ast/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (3)Versions (8)Used By (0)

PHP-Parser to php-ast
=====================

[](#php-parser-to-php-ast)

[![Build Status](https://camo.githubusercontent.com/b513a7c0d313ef3da366afc5ab3e848f147a640030ae279720e75525a36db045/68747470733a2f2f7472617669732d63692e6f72672f5479736f6e416e6472652f7068702d7061727365722d746f2d7068702d6173742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/TysonAndre/php-parser-to-php-ast) [![Build status (Windows)](https://camo.githubusercontent.com/ad6ed0e9111a12f3ac49c42bb640abac55c429280837c000a72f427ef99e4d5c/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f343168376170786d766d6b656331726a3f7376673d74727565)](https://ci.appveyor.com/project/TysonAndre/php-parser-to-php-ast)

This converts ASTs(Abstract Syntax Trees) from [PHP-Parser](https://github.com/nikic/PHP-Parser) to [php-ast](https://github.com/nikic/php-ast/). It can be used as a PHP-only implementation of php-ast. It can alternatively be used as a best-effort parser for syntactically valid PHP code.

Also see  (in progress, may have better results)

Supported [php-ast AST versions](https://github.com/nikic/php-ast#version-changelog): 40, 45, 50

Current Status
--------------

[](#current-status)

No tests are failing

- Need to normalize namespaces (Mostly done)

[Current Issues](https://github.com/TysonAndre/php-parser-to-php-ast/issues/)

- The test suite this is based off of covers common cases for Phan, but edge cases still remain. See [\#4](https://github.com/TysonAndre/php-parser-to-php-ast/issues/4)
- See [nikic/php-ast#78](https://github.com/nikic/php-ast/issues/78)

Remaining work:

- Translate PhpParser exception to a `\ParseError` instance

Usage
-----

[](#usage)

Using it as a slow substitute for php-ast

- [tests/ASTConverter/ConversionTest.php](https://github.com/TysonAndre/php-parser-to-php-ast/blob/master/tests/ASTConverter/ConversionTest.php)

Using it as an error-tolerant substitute for php-ast: (e.g. for use in IDEs)

- There are currently two modes: omitting errors and adding placeholders (e.g. `__INCOMPLETE_VARIABLE__`).
- Omitting errors only handles some common cases that come up while editing a file.
- Placeholders may change in the future.
- [tests/ASTConverter/ErrorTolerantConversionTest.php](https://github.com/TysonAndre/php-parser-to-php-ast/blob/master/tests/ASTConverter/ErrorTolerantConversionTest.php)
- If performance is an issue, cache previous results for a file's contents (in combination with the version used to generate the file `ASTConversion::ASTCONVERTER_VERSION`)

Running unit tests
------------------

[](#running-unit-tests)

To run unit tests, you must install [nikic/php-ast](https://github.com/nikic/php-ast). A version supporting AST versions 40 and/or 50 should be installed (`~0.1.5` is preferred)

- Then run `vendor/bin/phpunit`

Possible Future Enhancements
----------------------------

[](#possible-future-enhancements)

- [microsoft/tolerant-php-parser#113](https://github.com/microsoft/tolerant-php-parser/issues/113)See  (The library to convert between AST formats is broken(not finished implementing) and inefficient, waiting for stable API for tolerant-php-parser)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.1% 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 ~230 days

Total

5

Last Release

2255d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ffb9e612975be17e9ed477553358f2ced14a904b1031305ad4da55bb3861b332?d=identicon)[TysonAndre](/maintainers/TysonAndre)

---

Top Contributors

[![TysonAndre](https://avatars.githubusercontent.com/u/1904430?v=4)](https://github.com/TysonAndre "TysonAndre (77 commits)")[![TysonAndre-tmg](https://avatars.githubusercontent.com/u/110992834?v=4)](https://github.com/TysonAndre-tmg "TysonAndre-tmg (4 commits)")

---

Tags

astphpphp-astphp-parserphpparserast

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tysonandre-php-parser-to-php-ast/health.svg)

```
[![Health](https://phpackages.com/badges/tysonandre-php-parser-to-php-ast/health.svg)](https://phpackages.com/packages/tysonandre-php-parser-to-php-ast)
```

###  Alternatives

[ajthinking/archetype

Programmatically edit PHP and Laravel files.

2723.4M12](/packages/ajthinking-archetype)[atanamo/php-codeshift

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

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

A fast, simple and reliable HTML document parser for PHP.

1921.3M14](/packages/simplehtmldom-simplehtmldom)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23483.5k2](/packages/corveda-php-sandbox)[psx/sandbox

PHP sandbox to execute a safe subset of the PHP programming language

1745.8k1](/packages/psx-sandbox)[voku/simple-php-code-parser

Get a simple data structure from your php code.

485.6k3](/packages/voku-simple-php-code-parser)

PHPackages © 2026

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