Dumb Reasons to Hate PHP

  • You are here: Free PHP » Uncategorized » Dumb Reasons to Hate PHP

PHP just recently celebrated its 25th anniversary since it was first introduced, which is quite the achievement, considering it still powers a large slice of the Internet today. I don't write much PHP anymore myself as I've more or less moved on to new and different things, but I am incredibly grateful to PHP. It was one of the first “real” programming languages I really invested in to learn programming, and learn I did. I built real things, real websites with it, and also was involved in the community for a while. I saw the rise of Composer and Packagist replace the aging PEAR. I saw the release of PHP 7 and all the work that went into it the years prior leading up to it.

Now as expected whenever talking about PHP on the Internet, people are quick to grab their pitchforks and rehash the same classic criticisms of PHP over and over like a mantra. Is it to feel superior? Do they think they're doing a public service? I don't know. What I do know is that they're right to some extent; PHP isn't the best-designed language by any means, largely because it changed organically and incrementally over time. It certainly hasn't stopped PHP from becoming as popular as it has.

There are plenty of good reasons why PHP isn't the best language for many use-cases, and reasons why other languages are superior. I consider myself very experienced with it, so I speak from experience. Here are some examples just from memory:

  • The standard library, while fairly complete, doesn't really follow modern PHP's own best practices for API design, as it was largely created before PHP had things like namespaces and classes. This results in an odd disconnect with modern packages, and that weird mix of styles never really goes away.
  • The standard library also cares a lot about backwards compatibility, which is a good thing, but its also a double-edged sword. There are a lot of APIs and extensions that are soft-deprecated or generally not used in favor of higher-quality third-party packages.
  • The fact that every class file begins with <?php reminds you that PHP was originally just an html preprocessor and always runs inside the context of another file format. It makes sense, but its unusual and weird, especially since embedding PHP into html isn't even done at all in many frameworks which have dedicated templating languages instead.

There are probably others, but these don't keep me from remembering PHP with fondness as something that just works out of the box and has a lot of convenient features for web development.

What's strange to me though is that instead of reasonable complaints like these, people like to present complaints that don't make sense, aren't true, or are just plain silly. Let's take a look at just a couple that I've seen.

The syntax is strange and archaic!

This complaint doesn't really make much sense to me. PHP's syntax is very heavily inspired by C (which it is written in) and borrows many things from it. In fact, it fits right in with most of the languages in the C family of syntax. Just swap the dot operator for -> (which by the way is also lifted from C, its equivalent to (*struct_ptr).field), prepend all your variables with the $ sigil, and that's just about it. It's got your boring traditional class syntax that even JavaScript adopted, closures, and pretty much every modern convenience.

Granted, sigils probably remind you of Perl, but don't worry, they don't have crazy effects on data types like in Perl. Just think of it as part of the variable name and you'll be fine.

There are a few PHP-specific oddities in its syntax, like @ and using \ as a namespace separator, but these seem like really petty nitpicks to me.

It isn't modular!

This sort of complaint is really nebulous, and could stand to have some clarifying questions asked. Usually one means one of two things:

  • Everything is in a global namespace with no modular separation.
  • There is no modular way of packaging code.

Now both of these are just blatantly false. The first one is easy: PHP has namespaces, like Java, C#, or what-have-you. And they were added to the language in version 5.3, which was released in 2009! Now to be fair, there still exists a lot of codebases that were initially designed before then (like WordPress) that don't leverage namespaces everywhere because of this, and this includes the standard library itself. But generally namespaces have been adopted for some time, and any modern PHP codebase uses them well.

The second complaint is also false, but has a seed of truth i

Truncated by Planet PHP, read more at the original (another 5095 bytes)

Powered by Gewgley