This is cool, it's a tool to transpile it at build time so you are two steps removed from running PHP on the browser. I dissected this tool a while back and built another that lets you write and run PHP straight in the browser by doing the transformation on-the-fly. Wrote a blog post and all around it:
I think “run PHP in the browser” is overstating what this does, it's a naïve source-to-source translator and will not run any non-trivial PHP application, because JS and PHP have very different semantics. There are more sophisticated existing projects that actually try to compile PHP code or the PHP interpreter for the browser.
Yes, it's an approximate conversion favoring readable output over exact semantics, so it won't run WordPress. It might still be useful for smaller pieces of code. If you want to rewrite a PHP program in JS (which may be a bad idea…), it will do the most tedious step for you.
I wrote it just as a proof of concept. It was a warm-up before writing a similar tool for C to Rust source-to-source translation:
The point is to export some functions I suppose, ie. code server side form validation and have it converted to frontend code too (assuming it doesn't need to hit the database)
PHP -> WASM, can run anywhere WebAssembly runs: which is all modern browsers, embeddable into any language with a WASM runtime for it, or usable with a standalone WASM runtime:
Can you realistically compile an interpreted language into WASM without embedding an interpreter? If I remember right, PHP has “eval”, so how would WASM code deal with such a statement (that could evaluate any possible code) without embedding a PHP interpreter?
The comment you replied to linked to a WebAssembly build of the PHP interpreter.
But to answer your question, there's no fundamental difference between interpreted and compiled languages. If the program you want to compile doesn't use `eval`, and you can statically determine all the files it would include, why couldn't you compile it without including an interpreter?
There is a fundamental difference between dynamically typed and statically typed languages though. And if you want to AOT compile a dynamically typed language, then you're going to need to include code that looks awfully like an interpreter in the final binary.
Dynamic typing is really just passing around variables using an enumerated type. You don't need anything resembling an interpreter to do this and it's how the C extension APIs for many dynamic languages like Ruby and Lua work.
I think people in this thread are using 'dynamic typing' more as a shortcut to also mean features like eval, which does require a full interpreter or compiler.
This might be right, but it’s also true that most Common Lisp program can be compiled to machine code that’s very similar to what a C compiler would produce, except for the occasional runtime type check.
It depends what an interpreter means to you. You might need to use hash table lookups of variables and do switch cases on types in trickier cases where the compiler can't figure out what's going on, but you can leave out the main VM/interpreter part.
This right here is what the internet should be about. Stop debating whether this makes sense to do. It doesn't, and it doesn't have to. It's an absurd academic pursuit, and that makes the world a slightly better and more interesting place.
Very nice! It's interesting that some of the new features released in PHP 7.4 and 8 have direct parallels in JS. Here are a few examples: arrow functions, spread operator in arrays, weak maps, str_starts_with(), str_ends_with().
Probably a direct result of cross pollination between the communities. Since PHP was historically embedded into HTML you would get a lot of front end technology exposure.
I mean, it looks like their version of PHP arrays are very different, even "$a = $b" doesn't copy the the array, just references the same. I think anyone using this expecting to write PHP is in for some subtle and not so subtle surprises.
> This means we can connect to MySQL from the client side! That will be secure, right? ;-)
Not really, the MySQL server would need to support something such as webSocket or WebRTC to be able to directly connect to a browser (or just plain HTTP). So you'd still need either to modify MySQL or write a proxy server.
It's definitely fashionable to hate on PHP but its modern incarnation has no more warts than JavaScript and the two languages are probably abused by developers at about the same rate.
Still, it would have been neat to see this headline read "Run Scheme in the browser through Babel" or similar.
Highly highly subjective, js is tiny compared to PHP so you have all the issues with what_some_one wanted toName a function vs the standard PHP way. Not to mention js is very composable compared to most PHP.
This is icredible impressive, I have always thought php probably could be translated to js. I could definately see myself using this for future php projects.
https://francisco.io/blog/running-php-in-javascript/
Incidentally it's the #3 when you google "Run PHP in Javascript"