I originally meant to entitle this with "PHP, The Good Parts" but a quick google says there is actually a book of the same title. 😩 No matter though since the good parts of PHP are, in fact, actually great!
While PHP has made incredible progress in recent years, it continues to suffer ill repute. Some have even taken the extreme road of leaving PHP due to the bad rap alone. As of StackOverflow's Annual Developer Survey for 2020, PHP still ranks high among the languages programmers most want to stop using with over 60% of its users "dreading" it. 😢
Well, this is unfortunate. Although of course, considering that PHP has been the most popular server-side language in the last few decades, it is possible most of the projects currently running on it were written in a fashion acceptable to a different era. I imagine working with such projects to be quite far from pleasant (or actually, I might know 😅).
While every language has their own good and bad, PHP is considered to have far more bad; but it has a unique paradox about it. Despite being known as a systemically flawed and ill reputed language, some of the most massively successful projects in the world have been built with it. Heck, most projects of note seem to have been built with it! Renowned blogger and StackOverflow co-founder Jeff Atwood noted this back in 2008:
The TIOBE community index I linked above? It's written in PHP. Wikipedia, which is likely to be on the first page of anything you search for these days? Written in PHP. Digg, the social bookmarking service so wildly popular that a front page link can crush the beefiest of webservers? Written in PHP. WordPress, arguably the most popular blogging solution available at the moment? Written in PHP. YouTube, the most widely known video sharing site on the internet? Written in PHP. Facebook, the current billion-dollar zombie-poking social networking darling of venture capitalists everywhere? Written in PHP. (Update: While YouTube was originally written in PHP, it migrated to Python fairly early on, per Matt Cutts and Guido van Rossum.)
Notice a pattern here?
Some of the largest sites on the internet – sites you probably interact with on a daily basis – are written in PHP. If PHP sucks so profoundly, why is it powering so much of the internet?
- Jeff Atwood, PHP Sucks, But It Doesn't Matter
Now, this is a really curious case. Why, indeed, is a deeply flawed language powering so much of the internet? There must be redeeming qualities of this language we're not talking about i.e. the good parts.
So what exactly are the great parts? I actually don't think I can articulate it better than Keith Adams himself so you may want to check out what he said first hand yourself: https://slack.engineering/taking-php-seriously-cf7a60065329.
Now, I'm mostly just re-iterating here and anyone who has had some experience with a few server side language including PHP should be able to recognize these — the things we should add to the criteria with which we evaluate technologies; the virtues of PHP which do not lie in its language but in its environment.
State. The execution state of a PHP process is strictly confined to a single web request. It is created at the start of a request and destroyed upon completion. For its lifetime, this state is maintained independently of any other process — prior, subsequent, or concurrent. Absent any external stateful components, PHP is, by default, stateless. This provides a robust fault isolation between processes which ensure process
t+1 is not directly affected by process
t especially when the latter ends up in some limbo state.
Concurrency. PHP typically handles requests in a single threaded fashion. By operating within the context of a webserver, however, web requests themselves become a natural source of concurrency. And with web servers practically purpose built to handle those requests, this combination can be exploited to provide a reliable concurrency model.
Programmer Workflow. To say PHP improves the programmer's workflow may sound contentious but it is undeniable that PHP shows results, fast — and that matters a lot. The ability to "think; edit; reload" (to quote Keith Adams) means immediate feedback and a small feedback loop is essential to a rapid workflow. And while a similar behavior may be achievable with some other languages (e.g. via automations), such approaches are generally slower and introduce additional moving parts which occasionally do stop moving. 🤷♂️
Great to Greater
By intent or by accident, PHP is especially suitable for the web but the inherent language flaws have been a serious barrier in promoting the development of high quality software as well as a good reputation. As have been countlessly repeated, PHP makes it way easier to write crappy than elegant code.
However, the progress made to address its language level flaws are nothing short of impressive. The advent of Hack/HHVM and the release of PHP7+ introduced immense performance improvements and better language capabilities (a notable one is type declarations); the PHP Framework Interoperability Group has crafted PSR standards which have gained wide adoption in the community and among frameworks; frameworks and libraries (such as Symfony, Composer, PHP-Parser, etc.) have made bold headways to improve the quality, productivity, and rigor of PHP development, creating highly re-usable components, expediting standards adoption, etc. These may all be invisible to the outside but there have been huge movements inside the community to organize and advance the language.
Perhaps greatest the issue of PHP right now is not the language but its reputation. For over 2 decades, PHP's low barrier to entry has associated it with (sorry to say 😰) less skilled programmers and along with it a generally poor opinion of any PHP programmer.
It may take some more time before the advances within the community gains more recognition and for PHP to be seen more as a broad spectrum — with low barriers to entry on one end and rigorous development standards on the other. PHP need not just be the "get it done" tool which benefit businesses but also a respectable language for developers to be using.
Perhaps we can chalk it up to a lack of insight of PHP's virtues or simply the sheer number of excellent alternatives abounding (JS is booming like crazy recently); PHP's lacking popularity with some developer communities poorly reflect its excellent suitability for building modern web apps. Its often understated strengths — state isolation, reliable concurrency, and rapid programmer workflow — which make it reliable and productive far outweighs its language-level issues.
With the constant improvements rolling in on top of a battle tested base, PHP rapidly continues to move towards becoming a more reliable and enjoyable language for building quality software.