Archive for November, 2008

What’s with PHP? How I see it after 8 years.

Tuesday, November 11th, 2008

That’s right, I’ve been programming in PHP (not always full-time, and with a few breaks) for 8 years! I forget exactly what version I started with working for my dad in late 2000, but you can imagine the feature set at that time. Add to that the fact that I had little desire to craft myself into a professional programmer at the time, and we’re painting a pretty mundane picture.

It wasn’t until 2005, as I really started to care about programming languages, that I realized why PHP carried such a stigma. PHP added limited object-oriented functionality as an afterthought, not adding robust support for OO until version 5, in late 2004 (PHP was born in 1995). Considering that the OO paradigm had firmly taken root before PHP was even released, PHP’s rudimentary nature made it unattractive to ‘real’ programmers. Inconsistent naming conventions, questionable performance in complex applications (no longer a major concern… Facebook, Yahoo, etc.), and a community of self-taught web programmers made PHP an easy target for detractors.

Frankly, I agree with the detractors in most ways. Even though PHP has supported OO architecture for quite some time (in web years) at this point, its original procedural paradigm persists tenaciously in the PHP community. Reading through the source code of such popular products as ZenCart/OSCommerce, CakePHP, MediaWiki, and Drupal, (all of which I have dug into myself) you’ll find ad-hoc, incomplete, and often incorrect application of OO principals. The line between static classes and instantiated classes is often not drawn correctly, and simple patterns such as the Singleton and Factory are either nowhere to be seen or inexplicably applied. Sure, you can find plenty examples of folly in source code in other languages, but I think PHP stands out (second only to Perl, maybe) for having such a large proportion of ugly code.

For all the detractors’ fervor, there is no denying that PHP has moved mountains. I still don’t completely understand how or why PHP became such a major building block of the internet economy, but, lo and behold, millions of e-commerce sites, blogs, wikis, social networks and portals are powered by PHP. In terms of dollars, I’m sure the sites powered at least in part by PHP take in a significant chunk of the web’s weekly paycheck.

As I learn more about building software, PHP and the lamentable PHP source code I’ve had to work with become very unattractive to me. My experiences with Ruby (first) and Python (recently) — oh, and to be honest, Javascript — have spoiled me, made me want anything and everything to be an object with a pretty interface. On the other hand, while I’m reading the docs for manage.py (Django), encountering poor hosted support for Ruby and Python (on Dreamhost), and staring blankly at the Google App Engine instructions, I understand the appeal of software that runs the way you want when you simply place the source under your web directory.