WEB Advent 2008 / “Yet”

Have you ever wondered why PHP was invented? It’s relatively easy to find out how the language grew out of one of those scratch-an-itch situations that so often represent the genesis of open-source projects and how it evolved from there to become what it is today, but it’s not so easy to understand what has driven the developers to scratch the itch in specifically the way they have.

Naturally, the answer to this question is that there is no single answer. Each developer who contributed even a single line of code to the PHP platform did so specifically to solve his or her immediate problem in a manner that catered to his or her unique needs. This explains (at least in part) the schizophrenic nature of PHP’s API—if you have ever wondered why, for example, string manipulation functions seem to have more signatures than the UN Charter, all you need to do is realize that they have been the product of many different minds at many different times.

If there were a product statement for PHP, it’d probably be something like “only a drunken Martian could come up with this.” I don’t know anyone who programs in PHP and hasn’t, at some point or other, cursed some apparently mind-boggling PHP design decision, or who hasn’t become much more acquainted with the concept of “haystack” and “needle” than any one person should have to in a lifetime. I, myself, have been known to go through episodes of periodical rejection, during which I can’t stand a particular feature of PHP (and, often, of other products, but that’s a different story), but I haven’t given up on PHP—yet.

Strength or Weakness?

And so, PHP is the language that everybody loves to hate. Still, PHP is also one of the easiest languages to learn—and the two things are deeply interrelated: because it does not enforce any particular programming style over another, PHP has the unique ability among all languages to adapt to the developer’s own style and knowledge level, and evolve with it. As an insider, it’s actually funny to see endless discussions on newsgroups or the latest PHP-bashing entry on the Slashdot-of-the-day web site where people who aren’t familiar with our platform disdain its ludicrous awkwardness while marveling at its popularity.

The elegance of PHP, therefore, is in its inelegance. The cost of admission to this most wonderful of development platforms is the fact that the language feeds you as much rope as you want and, therefore, the threshold for writing bad code is as low as what’s required to write any code. With time, an experienced developer learns that the only reason why any particular functionality is not in PHP is that it’s not there—yet.

Picasso by Numbers

You can think of PHP as a blank canvas that comes with nearly all kinds of colors and paints you can imagine. If you are a solo artist, it’s carte blanche on which you can draw and paint at will—but, if you are in a team, the lack of direction can spell doom for your project.

That’s why frameworks are so popular within the PHP world (at the time of this writing, Wikipedia lists 34 PHP-based frameworks—a number second only to Java’s): they provide a consistent environment to which multiple people can contribute code that is—at least in theory—homogeneous in nature.

The flip-side of frameworks is, of course, that they force the programmer into adopting a specific pattern for software development and, therefore, the learning curve is much steeper than “plain old PHP.” Invariably, PHP developers who try to settle into a framework have the (often irresistible) urge to simply drop it and write their own, because, you see, there is no framework that does things the way he or she wants—yet.

And for the Rest of Us…

One of the undesirable consequences of the large number of frameworks that are available to PHP developers is the fact that it’s at the same time too easy and very difficult to give any of them too much importance. If you happen to develop code, targeting a particular framework should only be an option when you want to bring functionality that is otherwise available to PHP into it—say, integrate the base JSON functionality that is available in core so that it conforms to the particular way your framework functions.

If, on the other hand, you are trying to introduce a new technology to PHP for the first time, then it’s important that you at least consider the fact that a framework, no matter how popular it is, is not PHP. As such, porting functionality to a framework is a poor way to reach the PHP community at large, and can only contribute to furthering the balkanization of the PHP landscape, without any big-picture marketing or business benefits for anyone.

Ultimately, the PHP world is what we, as a community of volunteers and professionals, make of it. So far, we’ve done a decent job of keeping things together, even though there are some “interesting” times ahead. Luckily, we can all sit down, relax and enjoy these holidays with our families—and not worry about a thing… yet.

Other posts