Climbing the Abstract Syntax Tree
summary
PHP 7 adds an actual Abstract Syntax Tree between parser and compiler so compilation becomes 10–15% faster at the cost of more memory; the AST is a mutable data structure that supports constant folding and code generation (unparse) but may change formatting. Demonstrations include a tiny PHP lexer/parser/compiler that builds and executes an AST, use of PHP AST extension by Nikita Popov and the slower php-parser (userland) fallback, and a better-reflection proof‑of‑concept that monkey‑patches method bodies (setBodyFromClosure) which works in demos.
AI-written summary · about
chapters (10)
- 0:00Introduction to PHP internals
- 1:50Lexical analysis
- 5:22The parser and AST
- 10:07Understanding the AST
- 15:42Traversal and compilation
- 20:17Building a custom compiler
- 26:12Compiler execution
- 29:03Userland AST tools
- 34:06Reflection and monkey-patching
- 40:41Conclusion and Q&A








