Is PHP Getting Better?

Jun 29 2012

In many ways, I am not the average PHP developer. PHP was not my first language. I came to it after learning C, Perl, Java, JavaScript and others. And my initial reaction to PHP was, "What a funny little template language!" But through a long and convoluted career trajectory, I ended up as a professional PHP developer.

Why did I end up depending on PHP for my daily bread? There is one simple reason: It's everywhere. Project after project, client after client, I kept running into PHP. There were home grown utilities to fix. There were webmail clients to tune. There were blogs to write plugins for. And there were CMS systems to build out.

It's been three or four years since I transitioned from developer-who-happens-to-know-PHP to a PHP developer. Day in and day out I hack on PHP code. I wouldn't say that I've grown to love PHP, but I've certainly grown comfortable with PHP.

I know there is a constant stream of PHP cynicism. Like Perl before it it, PHP has no shortage of detractors. But I think PHP might be getting better.

The funny thing, though, is that it's not the language that's getting better, it's the community. I think there are four clear ways in which this is true:

  • A Move Toward OOP
  • Loaders
  • Libraries
  • Professionalization

I briefly explain each of these below. <!--break-->

A Move Toward OOP

In the last five years the trend in PHP has markedly be in favor of Object Oriented Programming. I'm not about to claim that all PHP is written in (proper) OOP style, but the big projects are all moving in that direction. Several fantastic OOP frameworks are now reaching maturity, and these are paving the way for a much broader range of OOP PHP apps.

Does this mean that instantly PHP will undergo a renaissance of elegant code? Perhaps not. But if fostered, OOP can vastly improve application design. And since these frameworks are enforcing certain pattern-based approaches, I think we are seeing the first fruits of a trend toward overall better PHP.

Loaders

With the rise of OOP, the PSR-0 standard was issued. This standard defines a way to map class names to file names, making it possible for autoloaders to take on the onus of loading files. With this, developers no longer have to track includes and build bizarre one-off systems for managing runtime loading.

PSR-0 was a community initiative. An ad hoc group developed the standard, and the community embraced it with surprising rapidity. And this seemingly simple change has shown two things:

  • The community can take responsibility for improvement.
  • Small conventional changes can have huge practical import.

Nowhere is this second point more evident than with PHP libraries.

Libraries

Loaders have given rise to a much-needed dependency management system, Composer. This is a game change for PHP. Suddenly, PHP developers have a wealth of libraries at their fingertips, and these libraries can be easily managed per application (instead of per system).

And this is an indication of a broader change in the PHP community: The rise of the PHP library is well underway. For a long time, integrating with PHP libraries was a pain, involving broad Google-based hunts for decent libraries. Too often, developers (myself included) just settled for (re-)implementing everything anew with each successive project.

But along with the advent of quality PHP frameworks and loaders has come the rise of stand-alone PHP libraries. The Symfony project is arguably leading the way, making most (if not all) of its components available as stand-alone packages. Sites such as Packagist aggregate libraries in much the way NPM has done it for the nascent Node.js platform.

Professionalization

A long standing criticism of PHP is that those who code in PHP are not "real developers". To some extent this criticism may be grounded in fact. Because (a) PHP is everywhere, even on the lowest of low end web hosting solutions, and (b) it has a low barrier of entry, PHP is a common "first language."

Oddly, this has become a target of criticism. Why is it that PHP's relative easiness indicates to others that it is in some way deficient? Over and over I hear critics claim that too many people who write PHP are "novices." Should we make our languages harder to learn so that we can keep the novices away? Let me answer that for you: No.

But on the flip side, it has been claimed that not enough PHP programmers are professionals. While such a claim runs the risk of breaking down into questions of interpreting the data, there is a way to frame it that does not lead down that path: It seems that many historical PHP projects were not designed following common design patterns and architectures. Real professionals know how to architect.

Perhaps the biggest cultural change in PHP is that many high-profile developers now are credentialed software developers interested in promoting good architecture, useful design patterns, and strong programming methodologies. And rather than leaving young coders to their empty editors, cursors blinking away, these developers are building toolchains that try to keep the simplicity so appealing about PHP itself, while also encouraging good programming.

Is It All Better?

Can the PHP developer claim total victory over the critics? No. PHP still isn't multi-threaded, still has all the quirks of its mixed heritage, and will forever call an utterable hash map and "array". So much of that is crystalized that I don't think it will every change.

But for all its warts, PHP is getting better. And given its vast market penetration, that is a good thing -- a trend we can all hope continues.