The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

PHP Internals

I'm interested in learning how the PHP parser works.

Can anyone suggest where I should begin ?
Lazy Web
Friday, August 11, 2006
Complete source code is available free at

Read the code, then ask your questions at the "php internals" mailing list, also at
Saturday, August 12, 2006

First of all, there is grammar description of PHP language.
This description then compilated in C code using Bison:
"Bison is a general-purpose parser generator that converts an annotated context-free grammar into an LALR(1) or GLR parser for that grammar."

Learn more about Bison, and you will know how PHP parser works.

Grammar description of PHP you can find in PHP sources.  php5-0.0/Zend/zend_language_parser.y

As a start you can look at php.ini file parser. It is implemented the same way as PHP language parser. zend_ini_parser.y

I hope this helps.
Pavel Vasilevich Send private email
Saturday, August 12, 2006
See this documentation

From my own experience - the PHP parser uses Flex + Bison to generate a lexer+parser in C. The Flex and Bison definitions are pretty much standard. So if you are familiar with these tools, just grab the latest PHP snapshot from and read  Zend/zend_language_scanner.l and Zend/zend_language_parser.y

The only quirk of the scanner is that it uses a custom skeleton file to make the scanner re-entrant, but this does not make the scanner harder to understand.
Vesselin Atanasov Send private email
Saturday, August 12, 2006
Thankyou Pavel and Vesselin for your comments.

The slides by Derick Rethans seem especially useful. They give a nice and simple overview of how PHP works.
Lazy Web
Saturday, August 12, 2006
This book may be a good place to start. Understanding how to extend it can be a good way to learn how it was written.
Jeff Send private email
Saturday, August 12, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz