You can write PHP in any language

July 12, 2021, – 100 days to offload count-down #81

The title of this post is the paraphrased warning of old

“You can write Fortran in any language.”

PHP is heralded as the pinnacle of bad web-development languages, largely because of it’s accessibility and wide-spread adoption by untrained people early on. A hellish pit of foot-shooters, security vulnerabilities, and harmless but irritating idiosyncrasies galore. But there is another side to this.

PHP has come a long way. What proved to be a turning point from a developers perspective was PHP 5.3 and the introduction of closures. The first usable Version was 5.6, the accumulated changes including generators, traits, real array syntax, variadic functions.

The perspective of a manager/architect is somewhat different. You want to tap into the apparently endless seeming supply of barely educated and therefore relatively cheap PHP developers, and balance that with a sufficiently performant runtime. The developers were and are there, and there are really good ones, too – the prejudice is not completely undeserved for the group of PHP programmers as a whole, but there are brilliant people there too. One had to put quite a bit of hardware into service to make PHP perform. And then Facebook saw that PHP just wasn’t up to par and developed and introduced hhvm. That was the breaking point, either PHP would somehow get it together or hhvm would supplant it.

PHP reacted, and they reacted in a good way – PHP is now compiled to an abstract syntax tree, allowing for systematic optimizations. It provides among other things, short lambdas, array unpacking, just-in-time compilation, optional strict type checks. While partial function application and the v2-pipe operator RFC were not approved, the RFC for a first-class citizen implementation for callables is coming, and with it Sara Golemons first pipe-operator implementation may get new traction - the RFC was never voted on, so while it’s marked as inactive, it’s still on the table.

Would I have gotten my way, I would not know about PHP – what turned out to be my first PHP project would have been implemented in ruby. But it is not all bad, a lot of the big PHP frameworks feel a lot like the java world I was so glad to leave behind - and we ignored those, wrote our own in-house framework, and we could do things in php - a way more functional approach, with reflection based preprocessing and code-generation as kind of poor-mans-macros, easier, faster and cleaner than java would have allowed back than.

My first web application I wrote in C++ in 1999. It used fastcgi and was blazing fast. After that I programmed in java, then one project in perl, followed by one j2ee service. Nowadays I experiment in my free time with erlang and elixier, lisp and am learning rust - and I’m envious, to a certain point, of people who make a living writing code in those languages - because I like their expressive powers, a lot of the stuff I do could be expressed so elegantly. But for more than 15 years now I program mostly in php, with a bit of C, javascript, tcl and whatnot sprinkled in, switching jobs only once seven years ago – I concentrate more on the taking care of family aspect of a life, and php is the tool my employer chose, and this is the constraint I accept and work with – after all, I can write neat programs in any language.