PHP internals info

The PHP programming language is written (mostly) in C. The resources below cover both how to modify the PHP language and the core PHP library, as well as how to develop custom extensions.

Main resources

The PHP Internals Book

The PHP Internals Book is the most comprehensive resource for learning how PHP works internally, and how the functionality can be updated. I'd recommend reading all of it, but here are a few choice articles which are pretty vital to read.

Also, the PHP parameter parsing doc is held in git, but mirrored.

Nikita Popov's blog

Nikic Popov has a blog. It's generally interesting, and has some quite in depth articles on PHP internals:

Julien Pauli's blog

On his blog, Julien Pauli has quite a few in-depth posts about PHP. He also has a presentation of how all the internal bits fit together.

Sample extension implementation details

Thomas Weinert has a comprehensive example of how to implement features in PHP internals, where each branch implements a single feature. The way to use this set of examples is to find the branch that contains what you want to implement, check it out, and then look at the commits in that branch to see what was done.

PHP Extension guide from Zend

Written by Dmitry Stogov, one of the core PHP developers, here is a guide to "Writing PHP Extensions". It covers:

You can also go directly to the repo with all the code.

Tpunt's articles

Other stuff

Debugging tools

If you're writing C code, you have probably made a poor life choice somewhere, and as a result, you should learn how to use valgrind and GDB.

Valgrind is a tool that checks that you don't have any (detectable) errors accessing memory in your program, such as 'reading from unitialized memory' or 'reading or writing from freed memory'. If you're writing PHP extension, it's worth running your test suite under valgrind before doing a release.

GDB is a command line debugger, that allows you to set breakpoints, step through code, inspect variables, and other things you would expect from a powerful debugger.


M4 is a macro processor used to configure PHP and PHP extensions. It is somewhat non-intuitive to use, and you may find notes on the M4 Macro Language useful. The fine M4 manual itself is also possibly useful.

Etiquette and RFCs

One thing that is difficult for people new to a community to understand is the etiquette and established attitudes that people who have already been contributing to that project may have. The following links are my personal interpretations of other people's feelings. A.k.a. they are certainly wrong to some extent, but still might be useful.

Miscellaneous info


The feature most commonly desired in PHP is generics. People have been thinking about it for a while, and there is a discussion about what would be required. In particular Nikic's notes on implementation are probably of interest.


The test suite used by PHP is well documented in the PHP internals book