What fate befall ye, StackOverflow netizens? How do you think in such backward ways?
At one time or another, I've found myself stuck with PHP. It's the most hassle-free server-side platform on my cheap hosting service, I worked in PHP for my college's website, and I've helped family members muck around with WordPress.
- Assigning to an array element may be sugar for assigning a whole new array to the variable, and the most convenient syntax for function arguments may cause them to be deeply copied, but PHP's classical object system corrects these flaws somewhat.
I wouldn't shy away from coding in PHP again if I had to, but I'd much rather compile to it. The right source language could compile all my data structures to objects, and it could infer all my anonymous functions' lexical closures.
The StackOverflow link I posted doesn't help much--I just found it amusing--but there are a few helpful options:
- Snowscript (https://github.com/runekaagaard/snowscript) is a CoffeeScript-like syntax sugar layer for PHP. It doesn't address any of my semantic problems with PHP, but it's something. (The OP of the StackOverflow thread linked to Snowscript in a comment.)
- Fructose (https://github.com/charliesome/Fructose) is a language which approximates Ruby and compiles to PHP. The main website is down, the GitHub project hasn't been updated for a year, and I don't see much documentation. But wait! The compiler code does manipulate lexical closures in some way, and the runtime library has object wrappers for arrays and other primitives, so I expect it to be pretty nice to work with.
- Pharen (http://scriptor.github.com/pharen/reference.html) is a lisp which compiles to PHP. Probably the most promising of all of these, not only does it have implicit lexical closures and PHP-object-system-related features, but it also has macros, and the language reference explicitly talks about tail call elimination. And hey, the compiler is written in PHP itself, so it should be possible to import the compiler and do eval at run time (whether or not Pharen is set up to do that out of the box).
 Pharen probably doesn't support TCE across multiple procedures, since it seems Pharen procedures can be passed directly to existing PHP utilities, which indicates they're implemented as (TCE-unfriendly) PHP procedures.