Tool Open source

TypePHP

TypePHP is an ahead-of-time compiler for PHP developed by Swoole. It parses PHP source and declarations, lowers function bodies and constants to C++17, and compiles the generated code into native machine code rather than interpreting Zend opcodes at runtime. The compiler is written entirely in PHP and self-hosts by compiling its own source code.

View repository Visit site Mentioned in 1 video ↓

Overview

The same codebase can produce native executables, loadable PHP extensions, shared libraries, and WASI or browser WebAssembly output. It supports compile-time native scalar types, high-precision numeric types, strongly typed containers, generated methods through attributes, and mixed C++/PHP projects; dynamic values, internal functions, reflection, and object metadata interoperate with the Zend runtime through PHPX. Its compatibility model intentionally covers a defined subset of PHP, with restrictions including declaration-only global scope and a required main() signature for binary mode.

TypePHP targets Linux, Windows, and macOS on x64 and ARM64, with PHP 8.4–8.5, a C++17 compiler, CMake, Composer, PHP development headers, and the matching PHP embed library required for relevant builds. It is distributed through Composer and the official repository under the GNU General Public License v3.0.

What TypePHP is used for

1 use taken from transcripts — each links to the moment in the video.

  • An ahead-of-time compiler that lowers PHP to C++17 and compiles it into native binaries. It can produce executable extensions or WebAssembly builds while remaining interoperable with the Zend runtime.

Videos mentioning TypePHP

1 in the library.