The original post: /r/php by /u/amfaultd on 2025-01-19 14:01:40.

I’ve started work on a new hobby project of mine - transforming a PHP file to valid JavaScript, so you could write your JS directly in PHP, and not need Livewire or the like (think ClojureScript, GleamJS, KotlinJS). Am not very far in the process yet, but the idea is pretty straight forward - create a JS transformer by parsing the PHP AST tree via nikic PHP-Parser and then create a JS compiler that puts the transformed results together.

Am writing this post to see if maybe someone else has done something like it already and have some potential pointers or gotchas to share. My overall goal would be to be able to write back-end and front-end in the same language, without resorting to expensive ajax calls for computation, since ideally we don’t want PHP execution for every single time front-end loads, just compile once and cache, or compile directly to .js files.