PHP Is Not A Good Language

I first encountered PHP about 20 years ago. I had set up a website, but I didn’t know how to make the forms on it respond to user input. Somebody at my Linux Users’ Group volunteered to hack the pages to make this possible. (It was, after all, the Linux Users’ Group site.) I looked at the code, and it sorta looked like Perl, but not quite. I didn’t understand it. Subsequently, that guy said that PHP was old fashioned, no one would be using it in the future. He was so wrong. Can you say “Facebook”?

In any case, it had solved my problem and I didn’t need to know anything about it, so I just let it drop.

Flash forward a year or two. I was running an accounting system on DOS emulation on top of Linux, along with a couple of other things. And suddenly, after an upgrade to the OS, this stopped working. Another problem had dogged the project before this as well. The system was fundamentally single-user and single platform. Not ideal as far as I was concerned.

Being a programmer, I was in a position to code up a multi-platform, multi-user substitute for this software. I surveyed some cross-platform toolkits. Things like that have a couple of problems. First, although they say they’re multi-platform, getting them working on multiple platforms can be a real challenge. And second, each requires quite a significant investment in learning the API for that solution. And when you’re dealing with user-interface coding, the investment in development can be really significant.

I spent a fairly significant amount of time doing research into possible solutions, but nothing really hit my “hot button”.

Then it occurred to me that the Web was probably the most ubiquitous “multiple platform” out there. And if you wanted multi-user, the web would certainly accommodate you there. The added bonus was that the user interface components didn’t require six months of study to rise to a reasonable expertise. It was, after all, HTML, which I mostly knew already. Only problem was, I didn’t know the other part which would make forms really possible: PHP. However, having previously coded in at least five languages, learning another language wasn’t a daunting challenge for me. And if it wasn’t some sort of toy language (e.g.┬áPascal), it might serve me well in other capacities.

So I set off to learn PHP. I bought some books on it, and started writing code. What I didn’t realize when I started, and what made the process that much easier, was that I’d written quite a bit in my third language, C. Turns out that PHP is a virtual copy of C for the web.

I’ve spent the last twenty years or so writing PHP code, hundreds of thousands of lines of code. I’ve written quite a bit of very useful software, In fact, my code runs the entire back end for my business and personal life.

By the way– PHP also runs on the command line and makes for quite a good scripting language. It’s a lot easier to write than some combination of Bash, AWK and Sed. Combined with a knowledge of SQL (which I had to acquire along the way), you’ve got a pretty versatile combination.

But at this point, PHP has acquired quite a few naysayers who claim PHP is just junk. When you pin them down, you find that it’s not really PHP itself which is deficient (though it does suffer from some odd design choices). PHP’s supposed deficiencies appear to lie in the idea that a lot of amateurs have written a lot of crap code with it. I’m not quite sure what “crap code” is. But it seems there’s a lot of it out there, waiting for the unsuspecting coder.

I rather suspect the complaints about PHP come from people who’ve spent months and years learning how to code in more “glamorous” languages like Java, Ruby and C#. Each one of these comes with its own significant learning curve, and a lot of just plain “baggage”. But they are favored by the language critics. Personally, I find university professors, language purists and language critics to be full of it. I think most of them have no real idea what they’re saying.

PHP is a pretty simple language to learn, particularly if you’ve ever studied C. I would recommend C as a first language for any programmer. It has massive utility (operating systems are written in it), and if you grab a readily available copy of The C Programming Language, it’s a fairly short runway from nothing to very useful, widely supported language.

It’s true that any novice can dig right in and write reasonably useful software with PHP. It may not be well-designed code, but it will get small jobs done. And the truth is, PHP is mainly for handling forms in HTML pages. That’s a pretty simple use case. There are countless libraries which can be added to PHP which extend its usefulness into fields where it really doesn’t belong. But that’s not the fault of the coders or language designers.

PHP is a workman’s language. You want web pages to play dixie and serve coffee, consider Ruby or Javascript. You want web pages to process user form data, PHP is your obvious answer. Virtually every web server in the world has built-in support for it, just as every browser you use will have support for Javascript. PHP isn’t glamorous, and it doesn’t have all kinds of the latest frills that afflict– er, supplement supposedly “modern” languages. It is utilitarian by design. It is a hugely practical language, much like C. Consider that the basic text on C (cited above) hasn’t changed hardly any in the last three decades. C just works. And so does PHP.

I’m sorry that a lot of amateurs write a lot of crap code in PHP. I see them on the PHP programmers mailing list, struggling with this or that programming concept, when their only exposure to coding is writing some throwaway BASIC code back in high school. You can’t keep people from trying, though they are kind of a pain on the PHP programmers mailing list. Most of us are professionals who don’t really have time to teach a full course on programming, which is what these people need.

In any case, there’s nothing wrong with PHP as a language, used in the use case for which it’s designed. You want matrix multiplication? Try APL. You want web server code? PHP is your best bet.