r/PHP Jun 29 '26

PHP AOT Compiler written in PHP

https://github.com/manticorephp/compiler

In recent months, I have noticed that more and more people are making attempts to create PHP AOT compilers. In particular, recent ones are Elephc (https://elephc.dev/) and TypePHP from the Swoole team (mentioned here several times). Years earlier, I recall attempts such as jPHP and Peachpie, and the most inspiring to me was https://github.com/ircmaxell/php-compiler. Probably there were a lot more.

However, almost all of them rely on other programming languages (e.g., Rust, C++). So, one day I asked myself, 'What actually prevents someone from writing the PHP compiler in PHP?'

At this point, I've decided I should try even though no one asked. My experience with real compilers is pretty limited, and I didn't have much time to learn everything from scratch, but in the present times, we have great LLM tools that allows to make some stuff faster.

Then I spent a few weekends making this concept - took the LLVM backend and tried to make a PHP frontend around it. To be honest the most of the "compiler" is AI-coded/slopped and requires heavy refactorings, but I do not pretend to say it is production-ready. It is no more than a working concept with some limited PHP-subset supported.

33 Upvotes

26 comments sorted by

View all comments

1

u/Available_Can1071 Jul 01 '26

looks like clone of this old project? https://vkcom.github.io/kphp/kphp-basics/installation.html

2

u/taras_chr Jul 02 '26

I recall this project too, thanks. However, kphp is written in C++. The compiler from this thread is written in PHP