Why is a language like PHP so popular?

Citește postarea în română

Share on:

Yes, PHP is probably the most popular programming language on the server side for the web at the moment. And it’s probably going to be for a long while…

It’s probably the best!

That’s not really it, just read on…

Why is it so easy to learn?

First of all, it’s the syntax. It’s not the best syntax out there, the reason is actually that it’s the most popular! I knew most of the syntax before I even looked at a “hello world” example, why? I’ve studied C in school, and people coming from Java had the same feeling.

Let’s see a few programming languages that are using this syntax: Java, C#, JavaScript, Perl, Go, PHP and, of course, C and C++, and between them you have most of the market and platforms.

Unlike (most) other languages listed above, it’s a lot easier to get started! You don’t have to create a main function, a class or anything else to get started, you just get down to it!

The good part is that you can make it as complex as you want (or need) to, these days there are Java-like classes and interfaces, horizontal inheritance with traits, functional programming with closures and anonymous functions, generators and, if you really are a hipster, even goto.

But PHP doesn’t sound so bad…

Now, there is an important detail that must be mentioned, PHP didn’t become popular because of the features mentioned above, but the features came to it because of its popularity, even “goto”. I don’t know why somebody would add goto to a language more than 10 years after its creation but that’s none of my business, nor is it important for the subject at hand.

The language became really popular with versions 3 and 4. By the time a decent OOP model is introduced, it had already gained a lot of popularity! Now, especially more so since PHP 7 is looking a whole lot more like a decent programming language, but 10 years ago it wasn’t the same story.

But node.js will probably surpass it!

Right… remember Ruby? Python? And others…

If you think about PHP, it has a major advantage and disadvantage, is very much as stateless as it can be.

With PHP you feel like it doesn’t know anything about the world, you have to bootstrap everything all the time. The advantage is that if you have a memory leak, most of the time, it’s ok. The current user will finish and everything will get cleared and nobody will have to care. And PHP had a lot of memory leaks when it started to became very popular and nobody seemed to mind.

When people started making cron jobs and other long running processes, this becomes a big issue and the need for features like explicit garbage collection became a must. That was added with version 5.3, which was released in 2009.

Normally, continuous running should not be a disadvantage, so the moral of this story is that it’s not necessarily an advantage either.

Nobody is going to build the next Google on it, but how about some blogs? Or even better, some shopping carts?

It just doesn’t have what it takes for something like the Google search engine and that’s ok because it was just not designed for that.

Another example for “not necessarily the best will win” is that WordPress is the most popular blogging platform.

Even more, people are using WordPress for all kind of weird things, basically you can do anything with it! And you should not blame the people using it, it’s not like you look what’s in your microwave when you buy it, you just want to have a warm meal. People forcing the limit of WordPress are doing the same, they can do what they need, so there is no good reason not to.

Should I ever use it?

Let’s take a couple of positive examples: Yahoo! and Facebook.
Yahoo! has been using it for a very long time on some of their products and in combination with other programming languages.

Facebook has been using it since the beginning because it is so easy to learn. They have been pushing the limit of the language in several occasions with: HipHop for PHP and more recently Hack, which was a very important motivational drive and a big influence for PHP 7.

Why all that trouble for a language? Because it’s just so easy to learn and use!

Usually, it’s a lot more important to release “now” then to have something “perfect” later, especially on the world wide web.

There is a very good reason why a language that is definitely not “the best”, but it is easy to learn is so popular online, while a programming language like C, which is way harder to learn, is more popular offline than online.

In other words, while definitely not being the best, PHP is most of the time just good enough.