PHP’s brighter future? On the “PHP the Right Way” project
I want to talk a little about a very promising project called “PHP: The Right Away.” But first, I’d like to give a brief rundown of why the project is of such interest to me.
First brushes with PHP
A few months back, I decided that I was going to learn PHP. Why? In all honesty, because a good friend of mine was designing a game in PHP–and had a fantastic idea for the game, which we’ll presumably finish one of these days–and I wanted to make a contribution. As simple as that. But I was reticent to tackle PHP because even as a beginning programmer I had already caught wind of the almost toxic levels of negativity surrounding the language.
The reality that I discovered wasn’t at all what I expected. Sure, there was plenty of spaghetti code out there (there’s also plenty of spaghetti code in C++, Java, take your pick…), but there were also a variety of frameworks and communities devoted to using PHP to all kinds of productive ends. I was also surprised at just how much of the internet runs on PHP. I guess that something like a third of the internet up and decided to quietly not mind the haters.
Hacker News explosion
About a month ago, I took it upon myself to summarize some of my impressions of the world of PHP in a piece titled “PHP: the quiet powerhouse.” In it, I made the simple and (I thought) not very audacious argument that PHP is extremely well suited for lots and lots of projects, as evinced by internet heavy hitters like Facebook and WordPress. I didn’t offer any glowing, effusive praise for the language or declare it to be the end-all be-all of web dev languages. I merely said that it’s still a great way to do lots of things and worthy of consideration in plenty of contexts.
But in spite of my relatively mild claims, I caught lots of flak here on the AppFog blog and in the post’s associated Hacker News thread. Fortunately, I also got a lot of very supportive comments from others who share my feelings about the language (thanks, folks!). And somewhere along the way, the post skyrocketed to #4 on the day on Hacker News. Given the article’s not-exactly-incendiary tone–it even had “quiet” in the title (!)–this surprised no one more than it surprised me.
The future of PHP
Surprisingly enough, I actually learned a great deal from this whole exchange, both about PHP itself and about the programming community in general. I got a much better sense of PHP’s very real (and sometimes very imagined) limitations. I picked up the juicy factoid that PHP began as a Perl library. I also gathered some valuable criticisms of PHP. The one that struck me as particularly salient involves not the language per se but rather the community and set of practices around it. It is this that the PHP: The Right Way project seeks to address.
And I learned just how much passion and vitriol comes pre-packaged with these debates. This turned out to be the real surprise. I was called ignorant and was asked if I was “even trying to make a valid point” (those being the safe-for-work comments). I’m thick skinned, so I was able to brush off the playground-style name-calling and to step back and marvel as the conversation unfolded into dozens upon dozens of comments, counter-comments, history lessons, call-outs, shout-outs, you name it.
Shedding some best-practices light on PHP
A while after making my first foray into the incendiary PHP debate, I came across the website for the PHP: The Right Way project, and the whole thrust of the project struck a deep chord with me. It’s an effort to (a) inform people about the real state of PHP, against a variety of channels of out-of-date information; and (b) to shine some potentially uncomfortable light on widespread but sub-optimal practices.
The introductory paragraph comes across almost like a manifesto:
There’s a lot of outdated information on the Web that leads PHP users astray, propagating bad practices and bad code. This must stop. PHP: The Right Way is an easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative tutorials around the Web.
The project is currently housed on GitHub and is indeed accepting pull requests (as well as translations into other languages). Josh Lockhart, the creator of the Slim framework, spearheaded the project with the help of Phil Sturgeon, Kris Jordan, and a slew of other contributors.
I was legitimately surprised by all of the following:
- PHP supports anonymous functions (since version 5.3).
- PHP actually has a command line server, which enables you to run PHP programs in development without using Apache or another server.
- Composer has been turned into a not-shabby-at-all package manager.
- PDO is a library that enables you to connect to multiple database types–relational, NoSQL, etc.–through the same API while avoiding direct injection vulnerabilities.
The PHP world has come out and surprised me once again. Most surprising for me was the plethora of command line tools that are now available. I honestly had no idea just how much the experience of PHP development can be like developing in other languages. If you’re used to developing using the text editor-command line-browser trifecta (as I am), then you’ll be more at home than ever in the world of PHP.
But to be clear, the main purpose of PHP: The Right Way isn’t just to be informative about where PHP is now and what has changed. It’s also about preventing all-too-prevalent errors. The site boldly refers to direct SQL injection, for example, as “terrible code.” References to “good” and “correct” code abound. For the authors, “good enough” isn’t good enough. Misconceptions have to be corrected and bad habits have to be phased out. At stake is the safety and viability of the vast realms of the internet that run on PHP.
The PHP: The Right Way project is the best attempt that I have yet seen to put the world of PHP on a better path. As many commenters on my original post noted, one of the “problems” with PHP–although it’s only a problem from a certain perspective–is that it poses so few barriers to entry for novice users.
There’s no way to put this delicately, but PHP is a language that makes beginners feel empowered (and rightfully so!) to write up their own PHP tutorials, blog posts, and documentation. This kind of democratic ethos is a wonderful thing–after all, it’s the same ethos that undergirds the open source community in its entirety–but this democratization has sometimes come at the expense of best practices, not to mention security (the aforementioned SQL injection problem being the most oft-cited).
But there are also people under the PHP umbrella who are seasoned veterans in the language and operate at an incredibly high level of sophistication. Often, they are in a far better position to judge the merits and demerits of the language–and to exert a benevolent influence on the PHP ecosystem. That strikes me as the core of the PHP: The Right Way’s mission.
I think it’s clear how best to respond to the group’s provocation: if you’re looking to make bold claims about what PHP necessarily is and isn’t, don’t make those claims on the basis of tutorials or blog posts written by PHP beginners. Ask people who are seasoned veterans in the language and in its corresponding best practices. They’re the ones who fully understand PHP’s breadth and power.
And if you already find yourself under the umbrella of the PHP ecosystem, there is a different provocation being sent in your direction: join the conversation, be more aware of your own coding practices, and make a contribution.