Swoole's team has open sourced TypePHP, an ahead-of-time compiler that translates PHP source into C++ and then into native machine code, producing native binaries, PHP extensions, or shared libraries. Unlike a bytecode cache, it doesn't interpret opcodes at runtime, instead generating statically-typed C++ for hot paths while still interoperating with the Zend runtime for dynamic values, reflection, and internal functions via PHPX. TypePHP is written entirely in PHP and is self-hosting, meaning its own compiler binary is built by compiling TypePHP's PHP source with itself. The release landed earlier than its planned October timeline.
Questions this post answers
What is TypePHP and how does it compile PHP code differently from a bytecode cache?
TypePHP is an ahead-of-time compiler from the Swoole team that translates PHP source code into C++ and then into native machine code. Unlike a bytecode cache or virtual machine, it does not interpret opcodes at runtime; instead it produces optimized native binaries, PHP extensions, or shared libraries that run directly on the CPU while still interoperating with the Zend runtime through PHPX. Developers evaluating PHP performance tools can follow releases like TypePHP as they land on daily.dev.
Does TypePHP still support dynamic PHP features like reflection when compiling to native code?
Yes, dynamic PHP values, internal functions, reflection, and object metadata continue to interoperate with the Zend runtime through a layer called PHPX, even though compiled user functions no longer execute as Zend opcodes. This lets TypePHP keep familiar PHP syntax while emitting statically-typed C++ for hot paths. Teams weighing native compilation trade-offs for PHP can track tools like TypePHP on daily.dev.
Is the TypePHP compiler itself written in PHP or in C/C++?
TypePHP is written entirely in PHP and is fully self-hosting: its tpc compiler binary is built by compiling the compiler's own PHP source code using TypePHP itself, with no C or C++ glue in the bootstrap chain. Curious developers exploring self-hosting compilers can keep up with projects like TypePHP via daily.dev.
2.4K Impressions1 Comment