Why PHP in 2019?

There are a lot of programming languages in the IT environment, yet few of them have as adverse a reputation as PHP. Is this accurate? And if so, why is one of the most used programming languages in the world so disliked? 🤔 Let’s find out. 🕵🏻‍♂️

A little of history

PHP was born in 1995 by the hand of the programmer Rasmus Lerdorf. His goal wasn’t too ambitious. He wanted to have a set of scripts for tracking the visits of his online resume. This explains PHP’s first name: ´Personal Home Page Tools´ (PHP Tools). PHP was not intended to be a programming language at all, but a set of tools. In fact, in the PHP official announcement it was presented as “a set of small tight CGI binaries written in C.”

Even though it was not intended to be a programming language, it quickly gained adoption. One of the main reasons was that there wasn’t a lot of programming languages that could be used for Web Development (the first web browser, Mosaic, was just born in 1993, so the Internet was still new). Existing languages like Ruby or Python required a steeper learning curve to create a simple webpage. They were also general-purpose languages used to develop different types of applications. PHP was meant for Web Development from the beginning.

Another thing that helped PHP to become one of the most used programming languages for Web Development was the boom of the dot-com bubble. Companies began to realize that they required an internet presence.

With time and help from the growing community, PHP became a general-purpose programming language with a simple way to develop Websites. Its name evolved as we know it today, a recursive acronym that means PHP: Hypertext Preprocessor.

Okay, but if it’s so great, how did it become so controversial?

As I mentioned before, PHP was not meant to be a Programming Language. In order to become one, it had to be modified by its creator, along with its community. Like all developers know, planning afterward always means trouble.

These troubles were translated into deficiencies compared to other programming languages that were planned to work well from the beginning.

One of PHP’s most common criticisms is its inconsistency, but don’t take my word for it. Let me show you an example:

If we explore the naming of the native functions that the language give us for string management we will find functions like these:

str_replace strpos substr

All three of them are meant to manipulate strings. The first function has “str” as a prefix and a “_“ to separate the words. The second uses the “str” prefix but doesn’t use the underscore to separate the words. And the last one doesn’t even use the “str” prefix or underscore at all. Instead it uses a postfix.

Now imagine that you need to guess the name of a function that searches a string into another string. In which convention would that be? Now do you get the point?

As you can see the inconsistency is clear. That kind of pattern happens with a lot of the internal functions of the language, not just with the ones that manipulate strings. That is kind of challenging when you try to remember which function to use. It also makes it difficult to be productive, requiring you to check the documentation over and over again.

Another downside was the leak of “basic stuff” that other programming languages provide from the beginning, such as typed properties (hopefully we will have it in PHP 7.4). Or such as an Object Oriented Programming paradigm out the box as Java does (you can’t develop in Java if it’s not Object Oriented). The return type hinting (recently added in PHP 7.1).

Or the lack of native data structures in older versions, the only native data structure in PHP was the array that is, in reality, a Hash table. But that means that you needed to create your own data structures from scratch when you needed it. Now thanks to SPL classes we have more options.

All those kinds of disadvantages are the main reasons (but not the only ones) that explain why PHP is so criticized by the purist of developers and fans of other languages.

Also, if we take into account the time from PHP’s birth until now, a lot of new programming languages have been created. These languages have more awareness about the details and actual needs of Web Development.

Then why use it in 2019?

Well, a lot of things happened since those days. Some of the concerns that the language had are still there, like the naming inconsistency. But a lot of others are not an issue anymore.

In the beginning, everyone used to program in PHP they way they wanted to. Since PHP doesn’t impose you a paradigm to do it, you could write an entire website in a single file, or you could do it with OOP, creating many files and classes as you need. Also, if you needed some third party library, you needed to download it manually and add it to your project.

Since then, PHP-FIG was born! FIG stands for “Framework Interoperability Group”. They are a group of people trying to figure out some standards for modern PHP development. They do that through PSR’s (PHP Standard Recommendations) that help developers use some standards in their applications and then turn it into an efficient and modern web application that will be very similar to others using the same standards.

Also, now we have Frameworks (a lot of them), like Symfony, Laravel, CakePHP, Zend, Yii, etc. Each one tries to give us a way to develop modern web applications based in PHP. In my opinion, these frameworks were the key for giving PHP a second breath. Thanks to them now we can develop in a faster, cleaner, and powerful way from tiny to big applications.

We also now have really useful tools like Composer, that resolves the problem of managing dependencies in a smart way, allowing us to have the latest version of a certain third-party library or even lock it to a specific version. It also helps us to have a big repository of third-party libraries that any developer can use easily.

According to TIOBE Index, an index of the most popular Programming Languages in the World, at the moment of writing this (February 2019) PHP is the 9th Language in the list, just behind C# and just above SQL and leaving behind languages like Swift (20th), Go (18th), and Ruby (16th). So clearly PHP is not dead at all. On the contrary, I think that it’s future is very promising.

Also, you can check the list of the most popular websites in the world and notice that at least 5 of them uses PHP in one way or another.

PHP is still one of the recommended programming languages to learn this year by several sites and PHP is used by 78.9% of all the websites whose server-side programming language we know.

Conclusion

PHP is far from the traditional programming language design standards. It was designed as a set of scripts that evolved into a programming language and now has evolved to become one of the most used for web development. And like any evolution, it is constantly adapting to the changes and to the needs of developers. It tries to become better and better, sometimes even taking advantage of some of the features that are already implemented by other programming languages, but that is just part of the evolution.

The main problem with PHP is not PHP at all, but us, the developers. From the beginning we’re trying to write applications without any concern about the standards, or the maintainability, without focusing in unit testing, or even in readability of the code that we made.

All of that resulted in a lot of old (and some new) Web Applications that right now seem to be unmaintainable, without structure, with PHP code mixed with HTML tags and Javascript or CSS code… This is the reason for the deepened unfounded hate of PHP.

Right now, PHP is a lot of times the ideal programming language for some Modern Web Applications. With it, we can generate code that will be maintainable, robust, fast, clean, and will easily connect with other popular technologies.

Here at Linio we use PHP for numerous projects. And right now we are still using it for upcoming projects and we are convinced that PHP is a good choice, as good as any other.

Don’t hate PHP, it doesn’t deserve it.

Share this: