finds.dev

nikic/PHP-Parser

A PHP parser written in PHP

View on GitHub

★ 17,449PHPBSD-3-Clauseupdated Jul 2026

// the take

nikic/PHP-Parser is the de facto standard for parsing PHP source into an AST, used under the hood by PHPStan, Psalm, PHP-CS-Fixer, and Rector. If you're writing a static analysis tool, a code transformation pipeline, or anything that needs to read or rewrite PHP code programmatically, this is what you reach for — there's no real competition. It handles everything from PHP 5.x through 8.4.

The formatting-preserving printer is genuinely impressive: you can modify a subtree and round-trip it back to code without mangling the surrounding whitespace and comments. The emulative lexer lets you parse PHP 8.x syntax on a PHP 7 runtime, which matters for tooling that ships independently of the projects it analyzes. Error recovery is solid — it produces a partial AST even for broken code, which is exactly what you need in an IDE integration or linter. The visitor/traverser pattern is well-designed; you can stack multiple visitors in one pass and short-circuit early, which keeps transforms fast on large codebases.

The AST is mutable by default, which makes it easy to accidentally corrupt a tree mid-traversal if you're not careful about cloning. There's no type inference built in — you get structural information, not semantic information, so figuring out what type a variable holds at a given point is your problem to solve (that's what PHPStan layers on top). The `PrettyPrinter\Standard` output style is non-configurable in terms of brace placement and indentation, so if you're generating new code rather than transforming existing code, you're stuck with its opinions. Documentation is good but the upgrade guides between major versions are the only place to find reasoning behind API design decisions — the inline API docs are thin.

We read the README, the directory tree and a key source file in July 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
17,449
Forks
1,127
Language
PHP
License
BSD-3-Clause
Last commit
11 Jul 2026

// nearby

If PHP-Parser isn't quite it.

All repos →