Is there anything like CoffeeScript for PHP?

I've been researching this a lot and at the moment it seems the answer is no. I'm the author of exactly such a project called Snowscript - it is far from complete, but the documentation is pretty good and some things do work. Would love to hear feedback of what you think about the syntax!


The short answer is "no." CoffeeScript rose to popularity because of a unique confluence of factors. For one, as Wesley points out, JavaScript has a monopoly on the browser platform, while PHP only has a monopoly on .php files. On your own servers, if you don't like PHP, you can just use Ruby, Python, Perl, or any of the myriad JVM or .NET languages.

Another factor is that JavaScript's design was something of an accident. Its creator, Brendan Eich, was told to "make it look like Java"; but semantically, it has more in common with Lisp and Smalltalk. CoffeeScript arguably provides a syntax that's a better fit with JavaScript's inner workings.

JavaScript's own syntactic evolution is severely hindered by the need to maintain compatibility with older browsers. PHP suffers no such limitations, as anyone who's transitioned their code from PHP4 to PHP5 can attest. If you want to make JavaScript a better language, you need a precompiler. If you want to make PHP a better language, post a feature request for PHP6. (Edit: In my original answer, I fell for an April Fool's joke claiming that PHP6 had been released in 2010. Obviously I'm not a PHP guy...)

All of that said, it could be cool to have a language that's like CoffeeScript for PHP. The ongoing success of WordPress, and its use on servers that users often have little control over, attests to PHP's unique place as a deployed language. It's also difficult to use PHP with alternative markup languages like Haml. Perhaps an alternative markup language combined with a fresh PHP syntax could produce a compelling enough reason for people to precompile their PHP.