back

by theanonymousone·1y ago·view on hn ↗
This "in a single file" property is probably the most unique, and maybe the most enviable feature of PHP. I don't think you can do it in any other language, except maybe by jumping through hoops (e.g. jbang and uv come close).
6 comments
You can bundle everything in a file in most programming languages. You may find it useful (for sysadmin purposes) only with scripting languages, because with compiled ones you generally "bundle" most of the software in the executable file.
I think a far more enviable thing is that by default the file IS the response body. You can punt on explaining basically the entire web stack until later. You can teach interactive server AND client-side programming without having to explain more about HTTP than GET, POST, path, and the bodies.

Curiously, all the things I used to love about the language I now consider major liabilities and footguns. Outside of wordpress I'd have a hard time recommending it—it's so different from other webserver setups you're likely to prolong your frustration. Not to mention it's an ugly language with an incredibly inconsistent runtime library.

You can definitely do it in Javascript but without a bundler it becomes quite the pain.

Also, you can do it in C - sqlite's "amalgamation" is proof of that, but they use a bundler tooling IIRC.

I do similar things with Elixir scripts, though commonly I still turn to PHP because there is some single file library that does what I want with a lot less ceremony than the Java variety would require.

There's also PsySH, https://psysh.org/, for being something other than a Common Lisp or BEAM interface it's a very nice REPL. Besides Picolisp and iex it's the interactive programming environment I use the most.

Go lets you embed arbitrary files into the binary it creates. If you do that and also compile it to be standalone you have a one-.exe solution.
I meant a single source file. Obviously any compiled language delivers one binary file or so.
Anyone remember the snews single file CMS? It was pretty great..