A couple of months back I read an article, perhaps you read it too (link at the end). Like all great articles, this one forced me to re-evaluate my thinking. The central premise was that unlike most other languages PHP suffers from bad design. So much so that it is actually systemic. Many test cases and examples were presented to prove the point. There were a few that I was already familiar with, and several that I hadn’t encountered. Here’s just a sample of the more basic ones:

echo phpversion()."\n";
if (NULL < -1) echo "NULL is less than -1\n";
if (NULL == 0) echo "NULL is somehow also equal to 0\n";
if ("foo" == TRUE) echo "the string foo equals TRUE\n";
if ("foo" == 0) echo "the string foo also equals 0\n";
if (TRUE != 0) echo "but TRUE doesn't equal 0\n";

The above outputs:

5.3.14
NULL is less than -1
NULL is somehow also equal to 0
the string foo equals TRUE
the string foo also equals 0
but TRUE doesn't equal 0

At first, I reacted to the article with a little incredulity. The tone of it reads with exasperation and annoyance, which is somewhat off-putting. But after giving it a little rest and returning to it, I had to admit that the author had many good points. The end result, for me, was that I was spurred on to begin re-evaluating other languages again – something I had been meaning to do for some time.

If you look at it honestly, there’s a number of things about PHP that just don’t make any sense. Some are quirks, unexpected behavior – some are downright bugs. One can make solid applications with PHP, developers are doing so all the time, including those at respected companies. I’ve personally written many applications in PHP that have proved efficient and stable – several I’m quite proud of. There’s also certainly something to be said for the ease with which PHP can be adopted and implemented. Still, all things considered, one has to wonder if the web would be more productive as a whole if developers weren’t silently working around PHP’s oddities.

Conclusion? I’m not certain that abandoning PHP entirely is necessary. However, learning another language in addition to PHP can only improve your abilities as a developer. Analyzing and understanding how other languages work will help you to think more via design principle and not simply as a PHP implementor. If you choose to use PHP, do so with knowledge. Get to know its flaws and idiosyncrasies and learn to avoid them (but do so with the realization that such quirks aren’t normal). Use a well-designed PHP framework, one that knows what it’s about and has shaped itself through strong design principles. One such framework is Lithium.

Here’s the article that got me thinking: PHP: a fractal of bad design

Posted in PHP.