Is PHP a badly designed programming language?

Yes, it’s a horribly designed language (read PHP: a fractal of bad design if there is any doubt in your mind), but by asking this question you’re misunderstanding PHP.

Let’s try to understand where PHP is coming from and what it is. This interview with Rasmus Lerdorf, creator of PHP, shines a lot of light on what PHP is and what it isn’t: Interview — PHP’s Creator, Rasmus Lerdorf

“Well, I didn’t plan PHP. I think in terms of solving problems, not in terms of software projects. I actually hate programming, but I love solving problems.”

One could argue that it’s a bit misleading to even call PHP designed. Sure, in some sense it’s designed, but the word designed, at least for me, conjures the image of someone with great experience that sat down for a year or two, and designed a language — this is how Clojure, C# and Haskell were created. That’s not what happened with PHP. Instead, I’d say that PHP was grown.

If you doubt this, check this out: Re: Flexible function naming

Rasmus: “htmlspecialchars was a very early function. Back when PHP had less than 100 functions and the function hashing mechanism was strlen(). In order to get a nice hash distribution of function names across the various function name lengths names were picked specifically to make them fit into a specific length bucket. This was circa late 1994 when PHP was a tool just for my own personal use and I wasn’t too worried about not being able to remember the few function names.”

The sentence above would make many computer scientists start turning in their graves at 1200RPM.

You need to understand that PHP was written by Rasmus Lerdorf more or less by accident as a constantly growing number of helper functions when doing web programming. If Haskell is a super-designed, well organized toolbox in titanium with lots of powerful but weird and arcane tools, PHP is three to four toolsheds in different color (one pink with green spots) filled with random but very useful and approachable tools that lacks cohesion.

I think Lerdorf says it best himself:

Rasmus: “In the end, what I think set PHP apart in the early days, and still does today, is that it always tries to find the shortest path to solving the Web problem. It does not try to be a general-purpose scripting language and anybody who’s looking to solve a Web problem will usually find a very direct solution through PHP. Many of the alternatives that claim to solve the Web problem are just too complex. When you need something up and working by Friday so you don’t have to spend all weekend leafing through 800-page manuals, PHP starts to look pretty good.”

Get it? Yes, from many points of view, PHP is a horrible language, but if you’re in a situation where you need the shortest possible way to solve a web-related problem, have little prior experience with web programming, and long-term consequences are of little concern, then PHP makes a starts making a lot more sense.

So you have a broken table?

You can go to the store, buy some tools, learn carpentry, and spend the weekend fixing the table and polishing it up…

… or you just fix the fucker with duct tape because people will be showing up to the party in two hours.

Fun Fun Function

A fun, personal and down-to-earth show about programming

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store