I've been writing PHP applications for the last 10 years. PHP is still, mostly thanks to Wordpress, the most widely used server-side language on the Internet (source). It is used on more than 82% of all websites. But why, with all that “glory”, some developers say it's a really bad language? They often use terms like "spaghetti code”, slow or even evil.
In order to understand the origin of these standings, I will briefly go over the history of PHP.
PHP stands for “Personal Home Page” …. well, at least it used to, back in the day when it was first created in 1995. The first version was, to put it nicely, not so good. Everything was messed up, a lot of html code mixed with dynamic code and includes all over the place. It also had a very limited set of features.
The version 2, called Form Interpreters (PHP/FI), was a step forward. This is a sample code from the early days:
Hey, you are using Netscape!
Sorry, that record does not exist
You have credits left in your account.
However, version 2 also lacked a lot of features, was inconsistent and wasn't designed to build web applications.
It wasn't until the next version that things started to change. PHP added support for multiple databases, public APIs, and the community contributed a lot of different modules, which developed into a massive set of features. At it’s peak PHP 3 was installed at about 10% of all web servers, at the time. This can be perceived as a really good success, when you take into consideration that it was actually a new language.
The Zend Engine is the open source scripting engine that interprets the PHP programming language. - Wikipedia
In 2000, Andi Gutmans and Zeev Suraski rewrote the core of PHP to improve performance and modularity thereby creating PHP 4. If you ask me, this was actually the first version of PHP, as we know it today. Only after this version, developers were able to build complex web applications that had good performance, and could be scaled to meet most of the requirements.
PHP got its current, major version in July 2004. Version 5 introduced additional performance improvements and most importantly, PHP gets classes, which enable the development of object-oriented applications (in PHP). With classes, the first frameworks started to emerge. Yes, there were frameworks in previous versions, but they can be considered as more of a library than a framework.
As you can see from the history of PHP a lot of things have changed between the versions. As of version 4, things have more or less maintained their backwards compatibility. Keep in mind that version 4 was developed mostly as a set of functions, while with version 5 things have become more organised with the objective approach. All the future releases are also going in that direction, making PHP even better.
The best and the worst feature of PHP
Imagine somebody gives you a ball of clay and tells you do make a cup out of it. Somebody will just make a dent in the ball and say it’s cup. Others would go as far as designing the handle and even making inscriptions on the cup.
This is PHP - one of the most flexible languages. It gives you the clay, and it’s up to you how you will use it. This is the best and the worst feature of PHP. It’s up to the developer to perfect his skills and learn how to model it properly.
There are endless ways how you can achieve the same result. Knowing the best one comes only from experience. Because of this flexibility, a lot of developers have actually started to use PHP, it was easy, and it always worked. But in some cases, developers were inexperienced and started to abuse that flexibility, which usually ended up in spaghetti code.
Spaghetti code is a pejorative term for source code that has a complex and tangled control structure, especially one using many GOTO statements, exceptions, threads, or other "unstructured" branching constructs. - Wikipedia
Yes, there are many: http://www.phpwtf.org/
There is no justification for this … but in my 10+ years of experience, I maybe encountered one or two of them. If you use any modern framework like Symfony or Webiny Framework, you won't have any of those problems, and they shouldn't really be the reason not to use PHP.
Not that other languages are doing any better -> yes I’m pointing a finger :)
Is it slow?
Does it really matter…almost 90% of the page load time is on the front-end, nothing to do with PHP.
But no, it's not slow, even if you decide to build RESTful APIs…it’s actually really fast. PHPs performance and scalability are proven on sites like Facebook, Wikipedia, Flicker, Digg and many more.
With PHP 7 (you ask where is version 6?) it's expected that we will get a 100% increase in speed, compared to PHP v5.
However, the performance also depends on how you write your application. This website shows how some of the native functions behave, performance-wise http://www.phpbench.com/. It's good to use it sometimes as a reference.
Is it better than Python, NodeJs, C++, .Net, Java... ?
Of course it is…it’s the best language in the galaxy.
I would be very foolish if I really meant that. I don’t know those languages so well to claim that one is better than the other. This just brings me back to the point I want to make:
a language is only as good as the developer behind it
So there is no point in arguing which language is better, we can only argue which developer is better :)