4 ms·
Write PHP code and package as Go-binaries?? The potential!
by erikrothoff 9y ago
Write PHP code and package as Go-binaries?? The potential!
- zbentley 9y agoEven if this included an interpreter, that wouldn't allow you to package anything besides the PHP runtime (e.g. the "php" executable etc) as a Go binary. You wouldn't be able to distribute PHP programs as go binaries; it would still be an interpreted language, so you'd still have to make sure your programs, and their dependencies, were correctly deployed to wherever you had installed the interpreter.
- andrewstuart2 9y agoWith a properly parsed AST, you could probably convert to Go's AST and compile down to the final Go binary, similarly to how you can write a new front-end for LLVM.
- zbentley 9y agoTheoretically, you almost could (with quite a bit of difficulty), but then there's the problem of "eval". You can "solve" that by embedding an interpreter (or a copy of your compiler) into your runtime, but most interpreted platforms in that situation consider the interpreter "good enough" and work on making optimizations (e.g. JIT compilation to native code) on it rather than making a static compiler.
- toast0 9y agoI mean, eval is a thing, and I'm sure people use it, but I don't recall using it much while a PHP developer. It's just more likely to footgun than anything else. I think you can credibly release a tool that will compile PHP into a standalone executable, as long as it doesn't call eval.