There was a popular article a few years back calling PHP a “fractal of bad design.” It was basically a re-telling of the things we all know that are frustrating about PHP, but it gained a huge amount of popularity especially in the spaces where people already think of PHP as a bad language.
Thankfully, these days, that post matters only as a piece of back story to explain the name Phil Sturgeon used for a now-extremely popular package, “Fractal”: purely so it could bump that article down in the Google rankings.
I love this story—because I think Phil is hilarious and clever.
I also love this story because I think that PHP does have some serious drawbacks, many of which are detailed in that article, but I also think that the truest type of love—just like love of your family members, love of the annoying-but-endearing member of your friend group, or love of your country—requires that you both acknowledge its faults and then love it nonetheless. “Dissent is the highest form of patriotism.” “The Church is a whore, but she’s my mother.”
Last week I was on a podcast (How To Code Well Podcast – Why Is Laravel So Good!) in which the host laughingly asked, “wait, you were moving to Ruby but you came back? Why?”
It’s easy to get defensive when you’ve aligned yourself with a thing. “I’m a PHP programmer and someone implied it isn’t a joy to write with; I’m big mad!” But the thing is, first of all, I’m a programmer who happens to be writing PHP these days. PHP doesn’t define me. And second of all, if you think PHP is the most enjoyable language to write purely based on syntax then you likely haven’t written in other languages like Ruby.
Anyone who’s worked with Ruby knows it’s a joy to write; PHP is a lot of things, but syntactically beautiful is not one of them. Ruby is like the slick new sports car that you drove around at the dealership once, while PHP is more like your ten-year-old Corolla back in the garage.
In fact, I constantly describe my attitude toward PHP by saying “I want to write PHP like it’s Ruby.”
So… why don’t I just write Ruby? Why work with PHP at all? Turns out… it actually has a lot going for it.
I can deploy PHP anywhere I want
Have you ever tried to host a Ruby app yourself? Have you ever paid a Heroku bill? Have you ever tried running .NET on your own server? Have you ever tried to build a full stack Node application?
I can write PHP however I want
Many other languages tout the fact that there is a single canonical way to write them—to the point when some actually have formatters built into the language itself. I don’t hate that idea, but I do have one concern: if the people working in the core of PHP today were to enforce a standard PHP syntax, I wouldn’t want to write it anymore, because I don’t want to write PHP the way they do.
But… because PHP is so flexible, it doesn’t matter. I’m going to keep writing my Ruby-esque PHP, concise and absent of docblocks and return type hints; and they’ll write their Java-esque PHP, all verbose and enterprise-y; and most importantly, we each will benefit from the others’ contributions because we’re working in the same language and ecosystem.
PHP is a dynamic language. It’s duck-typed. Its type system is entirely optional. There is room for me and room for them and room for everyone else in-between and PHP just keeps chugging along.
There is a lot I can do, easily, with PHP
I don’t have to compile PHP. I can write a simple script that’s just a few lines and run it right in PHP. I can run it from my console, throw a single file up on a server, build a complex custom full stack web app, easily build CMSes and APIs and forums and wikis and blogs and admin panels and shopping carts and much, much more.
The ecosystem of tooling is incredible. No other language has this many packages available to make it possible for you to do this many things.
You can make money as a PHP developer almost immediately
Developing for WordPress is a completely acceptable long-term occupation—but it’s also a super easy introduction into the world of building web sites with PHP, and a space where someone can make money as they choose to transition to some other sector of PHP. Again, this is relatively unique to PHP, and I love it.
Turns out, it’s even great for custom web apps
You might be tempted to think that I’m saying PHP works well for CMSes and Wikis, but that other languages and tools win out for custom web application development.
But even there—with competition like Ruby on Rails, full-stack Node, ASP.NET, and Elixir—PHP shines. Just look at the list of tools and services and pre-built components you get when you’re working with Laravel and Symfony. How many rich communities we have around full-stack web application development frameworks—not just one, or two, but at least five major web frameworks (Laravel, Symfony, Cake, CodeIgniter, and Yii).
I could go on for days about the incredibly rich and robust ecosystem of tools, training, platforms, and services that support a web application developer who wants to work in PHP, but I won’t.
Let’s just leave it here: there is so much we can do with PHP. It has warts, for sure. I don’t care if the parameter order of its native functions are internally consistent with string methods vs. array methods; they’re still confusing as hell. But, in the end, that’s a minor annoyance. Yes, I wish my code could be more terse… but we did just get single-line closures! Baby steps!
And more importantly than that… syntax is not all that makes a language. Its communities do. Its tooling. Its supporting services. Its frameworks and components. Its education. Its ease-of-learning. Its ease-of-deploying. Its flexibility.
So, there it is. PHP is my annoying-but-lovable friend. Acknowledging its constraints doesn’t make me love it less; it makes my love for it more real. I’m not sticking my head in the ground and pretending I can’t hear the criticisms. Instead, I share them… and that doesn’t diminish my appreciation for the Programming Language With the Stupidest Acronym Of All, PHP: Hypertext Preprocessor.