PHP: the quiet powerhouse
It’s been very interesting beginning my trajectory in web development in 2012. I come to all of this at a time when PHP is no longer trendy and has caught flak in certain corners for quite some time. A lot of this probably has to do with the fact that PHP has been around for a while and (developers get bored easily) is now far from the only game in town for developing dynamic web applications.
Dozens of new language-specific communities have now entered the fray and brought along their legions of devotees with them, and many of those devotees see PHP as being passé. I even had the following happen to me, and this is absolutely a true story and can be verified by our VP of Operations, Richard Kotulski: I was in an elevator with O’Reilly’s very good “PHP Cookbook” in hand and an older gentleman scoffed at me and said, “PHP? What is this, 1920?” This really, actually happened. I doubt it would’ve have happened if I had had a Python or Ruby book in my hand.
I find it more than a little strange that PHP is simultaneously (a) out of fashion, and yet (b) absolutely everywhere. It powers an absolutely vast, almost cosmic number of websites. A few examples among millions: MediaWiki, on which Wikipedia is based, was written in PHP. It’s common knowledge that Facebook’s front end is written in PHP (although they now use the homemade HipHop to convert PHP to C++ on the back end).
What else? Oh, you know, Digg, WordPress, Flickr, and YouTube (originally). (Props to Jeff Atwood at Coding Horror for this list, though I disagree with the general thrust of the post in which the list is found.)
That should put to rest any doubts that PHP isn’t scalable. If anything, the onus is now on other languages to show that they can live up to the many already-existing accomplishments of PHP.
I also find this attitude toward PHP to be quite unfortunate. Why? Well, one reason has already been made clear: PHP does lots and lots of heavy lifting out there. It has more than proven itself.
But I also think that it might be the best language to use in gaining an understanding of the fundamentals of web development. This is my conclusion after spending some time with the same “PHP Cookbook” mentioned above and coding an app and deploying it on AppFog.
Now, let me warn you: this app isn’t exactly going to be garnering any awards any time soon. I put it together in a few hours having never touched PHP. But it nonetheless served as a fairly instructive introduction to aspects of PHP development.
I think PHP is the perfect language for beginning web development for two reasons:
- Direct HTML embedding. There are now more options available than ever for rendering HTML, from ERB to haml to jade to EJS and beyond. With PHP, HTML rendering of the type that you would use in a Rails project, for example, can be safely side-stepped, because the language was simply built with the intention of being readily embeddable into HTML.
<?php insert_code_here ?> is your one-way ticket to getting actual executable code into your HTML. This can be quite useful for apps at all levels of complexity.
For a simple app like the one I made, the barriers to entry in terms of knowledge accumulation were far lower than they were for Rails or node or anything else I’ve used. The distance between zero and producing something with functionality that involves sharing variables across pages, performing operations on those variables, and returning values elsewhere, was much shorter than it would have been using other languages/frameworks.
The other great thing about PHP is that although I did all of this using native code, there’s an absolutely vast range of frameworks designed to enable you to produce fully functional apps without having to do spend hours putting down boilerplate code in your text editor. AppFog, for example, offers direct support for a number of such frameworks, from Drupal to WordPress, with more on the way.
One last great thing about PHP: if you wish, you can use PHP without recourse to an MVC-style framework, as I did on my app. This means you can hit the ground running without learning to develop within a broader framework. But if your projects demands a level of sophistication that requires an MVC-style framework, platforms like Symfony and Yii allow you to do that, too.
No web development language outside of PHP grants you the kind of flexibility to both (a) produce genuine functionality from scratch, outside of an MVC framework, and also to (b) work within the bounds of MVC in deeply sophisticated ways if you wish.
In sum, PHP might not be the hottest thing on Hacker News or GitHub. But it is versatile, incredibly capacious, and more than worth considering for projects of all levels of sophistication.
Next week, I’ll share some of my experiences with deploying on AppFog. Until then, Dear Reader!