TypePHP: Compile PHP to Native Binaries (AOT) | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com) [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles  ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

  [ home ](https://msaied.com)    [ articles ](https://msaied.com/articles)    Compile PHP to Native Binaries with TypePHP        On this page       1. [  TypePHP: An AOT Compiler for PHP ](#typephp-an-aot-compiler-for-php)
2. [  How TypePHP Works ](#how-typephp-works)
3. [  Familiar Syntax, Compile-Time Types ](#familiar-syntax-compile-time-types)
4. [  Fully Self-Hosting ](#fully-self-hosting)
5. [  What This Means for PHP Developers ](#what-this-means-for-php-developers)
6. [  Getting Started ](#getting-started)
7. [  Key Takeaways ](#key-takeaways)

  ![Compile PHP to Native Binaries with TypePHP](https://cdn.msaied.com/599/a0eb0516fcca2a7c2e83f4aabf206988.png)

 [  Open Source ](https://msaied.com/articles?category=open-source) [  PHP ](https://msaied.com/articles?category=php)  #TypePHP   #AOT Compiler   #PHP Performance   #Swoole   #Native Binaries   #PHP Tooling  

 Compile PHP to Native Binaries with TypePHP 
=============================================

     26 Aug 2026      3 min read    ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said  

       Table of contents

1. [  01   TypePHP: An AOT Compiler for PHP  ](#typephp-an-aot-compiler-for-php)
2. [  02   How TypePHP Works  ](#how-typephp-works)
3. [  03   Familiar Syntax, Compile-Time Types  ](#familiar-syntax-compile-time-types)
4. [  04   Fully Self-Hosting  ](#fully-self-hosting)
5. [  05   What This Means for PHP Developers  ](#what-this-means-for-php-developers)
6. [  06   Getting Started  ](#getting-started)
7. [  07   Key Takeaways  ](#key-takeaways)

 TypePHP: An AOT Compiler for PHP
--------------------------------

The [Swoole](https://github.com/swoole) team has open-sourced [TypePHP](https://github.com/swoole/typephp), an Ahead-Of-Time (AOT) compiler that translates PHP source code into native machine code. The project was originally slated for an October release but shipped earlier than planned, as noted by Albert Chen on X.

How TypePHP Works
-----------------

TypePHP takes a fundamentally different approach from the tools most PHP developers are used to:

1. **PHP source → C++** — TypePHP parses your PHP code and emits equivalent C++ source.
2. **C++ → native binary** — The generated C++ is compiled down to a native machine-code binary that runs directly on the CPU.
3. **No opcode interpretation at runtime** — Unlike OPcache or a traditional PHP VM, there are no Zend opcodes being interpreted once a function has been compiled.

```bash
PHP source code
      │
      ▼
  TypePHP (tpc)
      │
      ▼
  C++ source
      │
      ▼
 Native binary

```

### Familiar Syntax, Compile-Time Types

TypePHP keeps standard PHP syntax intact and layers on compile-time type information. This allows the compiler to emit fast, statically-typed C++ for hot paths. Dynamic PHP values, internal functions, reflection, and object metadata continue to interoperate with the Zend runtime through **PHPX**, so you are not losing access to the broader PHP ecosystem.

### Fully Self-Hosting

One of the more remarkable aspects of TypePHP is that it is written entirely in PHP and is fully self-hosting. The `tpc` compiler binary is produced by compiling the compiler's own PHP source code with TypePHP itself. The entire bootstrap chain is pure PHP — there is no C or C++ glue code inside the compiler.

What This Means for PHP Developers
----------------------------------

For Laravel and PHP developers, TypePHP represents a significant shift in what is possible with the language:

- **Performance ceiling rises** — Native binaries eliminate interpreter overhead for compiled functions.
- **Distribution simplifies** — A self-contained binary can be shipped without requiring a PHP runtime on the target machine.
- **Type discipline pays off** — Code with explicit type annotations gives the compiler more information to generate optimised C++.
- **Zend interop is preserved** — Dynamic features, extensions, and reflection still work through the PHPX bridge, so existing libraries are not immediately stranded.
- **Pure-PHP toolchain** — No C/C++ knowledge is required to work with or contribute to the compiler itself.

Getting Started
---------------

The project is available on GitHub under the Swoole organisation. Full documentation and additional details are on the [TypePHP site](https://swoole.com/aot/en).

```bash
# Clone the repository
git clone https://github.com/swoole/typephp

```

Refer to the official docs for build instructions, supported PHP syntax, and interoperability notes before using TypePHP in a production context.

Key Takeaways
-------------

- TypePHP is an AOT compiler that converts PHP → C++ → native machine code.
- Compiled functions bypass Zend opcode interpretation entirely.
- Compile-time type information drives C++ code generation for hot paths.
- Dynamic PHP features continue to work via the PHPX Zend runtime bridge.
- The compiler is self-hosting and written entirely in PHP.
- The project was released early by the Swoole team ahead of its planned October launch.

---

*Source: [Laravel News — Compile PHP to Native Binaries with TypePHP](https://laravel-news.com/typephp-compile-php-native-binaries)*

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fcompile-php-to-native-binaries-with-typephp&text=Compile+PHP+to+Native+Binaries+with+TypePHP) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmsaied.com%2Farticles%2Fcompile-php-to-native-binaries-with-typephp) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  What is TypePHP and how does it differ from OPcache?        TypePHP is an Ahead-Of-Time (AOT) compiler that translates PHP source code into C++ and then into native machine code. Unlike OPcache, which caches Zend opcodes that are still interpreted at runtime, TypePHP generates native binaries that run directly on the CPU without any opcode interpretation. 

      Q02  Does TypePHP break compatibility with existing PHP extensions and dynamic features?        No. Dynamic PHP values, internal functions, reflection, and object metadata continue to interoperate with the Zend runtime through PHPX, so existing libraries and dynamic language features are not lost after compilation. 

      Q03  Is TypePHP written in PHP or does it require a C/C++ toolchain to develop?        TypePHP is written entirely in PHP and is fully self-hosting — the tpc compiler binary is built by compiling the compiler's own PHP source with TypePHP. There is no C or C++ glue code inside the compiler itself, though a C++ compiler is needed to compile the generated output. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://msaied.com/articles) 

 [ ![Multi-Tenant SaaS with Laravel: Isolating Tenant Data Using Row-Level Scoping](https://cdn.msaied.com/594/c38a3d613735b3f43e77683aeb0cce84.png) laravel multi-tenancy saas 

### Multi-Tenant SaaS with Laravel: Isolating Tenant Data Using Row-Level Scoping

Row-level multi-tenancy keeps your schema simple but demands discipline. Learn how to enforce tenant isolation...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 26 Aug 2026     3 min read  

  Read    

 ](https://msaied.com/articles/multi-tenant-saas-with-laravel-isolating-tenant-data-using-row-level-scoping) [ ![Query Binding Masking and whereBinary() in Laravel 13.27](https://cdn.msaied.com/597/bd82bbbaee7d7826a7a3a2f4e8b77330.png) Laravel 13.27 Eloquent Query Builder 

### Query Binding Masking and whereBinary() in Laravel 13.27

Laravel 13.27 ships query binding masking for safer exception messages, a whereBinary() family for byte-exact...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 26 Aug 2026     4 min read  

  Read    

 ](https://msaied.com/articles/query-binding-masking-and-wherebinary-in-laravel-1327) [ ![Laravel Boost v2.6.0: Testing Best Practices Skill and Read-Only DB Transactions](https://cdn.msaied.com/595/80a42be71329f6ac99af4be159b7497d.png) Laravel Boost Testing MCP 

### Laravel Boost v2.6.0: Testing Best Practices Skill and Read-Only DB Transactions

Laravel Boost v2.6.0 ships a unified testing-best-practices skill for AI coding agents, database-enforced read...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 26 Aug 2026     3 min read  

  Read    

 ](https://msaied.com/articles/laravel-boost-v260-testing-best-practices-skill-and-read-only-db-transactions) 

   [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

Explore

- [Home](https://msaied.com)
- [Projects](https://msaied.com/projects)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [Contact](https://msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
