PHP to JavaScript compiler

PHP to JavaScript compiler

For a few years now I have been working “on and off” on a compiler that converts PHP to JavaScript. There is something similar with Niklas von Herztens php.js, but my engine is not a VM but a parser and compiler written in PHP. While the resulting JavaScript still requires a small runtime (~ 50 K compressed), the main work is done in PHP.

Here is a little online demo. (Output is written to the browser console.)

Most of the features that are important in everyday use as well as a whole range of special properties of PHP (references, iterators, output buffering, anonymous functions, magic methods, ArrayAccess and many more) have already been implemented and the compiler also passes most of the PHP-native unit tests (if relevant). The biggest missing areas are the filesystem, traits and generators. What is all this for? Good question. For me it was mainly a finger exercise for JavaScript programming and the attraction of the detailed understanding of the background of PHP. Admittedly, I was also motivated by the increasing fragmentation in modern web development (HTML, CSS, PHP, MySQL, JavaScript, client / server interaction).

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,