If you take a look at some results on google or if you browse reddit on a regular basis, you’ve probably came across a blog post or a forum thread entitled Why PHP sucks or PHP is the worst programming language ever, Stop using PHP please etc….
In fact, if you type PHP is bad in google , this is what you get :
As Google says : It’s about 367’000’000 results but if you take a look at the results on the first page you get the idea, a lot of people hate PHP. Some hate it for valid reasons and others are just plain stupid elitists who rant on every other software than their own.
Yes, PHP used to be bad
Just to make things clear, I started tinkering with PHP with version 5.3 in 2010 I think, so I never worked with older versions of the language. (No I don’t use PHP4 constructors) But, it is not difficult to find old PHP code on the internet, just take a look at the PEAR libraries.
The fact is, PHP didn’t really start as a full-blown programming language, It was just a set of tools named Personal Home Page Tools which have grown over time in a programming language. That explains the inconsistent naming and weird ordering of functions parameters. And I must admit there is some stuff I don’t like about this language :
- The names of built-in functions are inconsistent (isset(), is_null())
- Functions arguments are inconsistent
- Case-insensitive functions but case-sensitive variables
- Other minor details
PHP is popular
Yes, this is something you can’t deny, PHP is very popular on the web thanks to a lot of hosting companies. What makes the language so popular in my opinion is the combo : Shared hosting providers / Wordpress.
Most hosting providers support the LAMP stack by default and you just have to drag and drop the files on the server and you’re good to go. Some of theme even offer those one-click install of Wordpress and other CMS. This contribute to this high “Market share”.
This is one of the things that gives PHP a bad reputation : The old, crappy, poorly coded, bug ridden legacy projects. At my current job, I’m in charge of an old project written in PHP that doesn’t use any framework or libraries (completely built from scratch), has no correct routing (every page is a subfolder), and doesn’t use a templating engine (a lot of
<php echo $var ?> in the middle of the html).
The tweet below pretty much sums it up.
Sadly, the internet is filled with such legacy crap and I can’t blame anyone who worked on such project to develop nothing but pure hatred for PHP.
If the code is bad, there’s a reason
Ok so this applies to all programming languages, If your code is bad, don’t blame the language. If your C program overload the memory, you did something bad, not the language, not the C compiler. (or you clearly not have enough RAM and you are responsible)
And that’s what I want to say : There’s too much bad PHP code out there (did I say wordpress ?) and too many projects filled with poorly designed codebase. Also, if you search for a PHP tutorial on google, you’ll find hundreds of tutorials that doesn’t teach you what the language can do and many of these will even give you perfect examples of what you shouldn’t do.
If you want to learn more about PHP, at first I would learn the basics (syntax, conditions and loops) and then move to a good tutorial such as Php The Right Way
Things got better
Hell yeah things got better, coding in PHP on a modern project is awesome. I work on a regular basis on Symfony 2 projects at work and with Laravel at home as well and I can really say that it becomes a real pleasure to create web applications and solve problems with them. If we take a look at a Symfony 2 project, we find everything a modern application has such as an MVC pattern, a package manager, CLI utilities and much more.
The latest versions really tried to make the language cleaner (go take a look at the improvements in PHP 7)
In the community of web development (and software development as well), everything sucks all the time. People say ruby is slow it sucks, OOP is stupid, functional programming is better, Java sucks etc… And don’t get me wrong I love trolling Java users from time to time but still, great projects exists with Java (PhpStorm and other JetBrains IDE, Jenkins, elasticsearch among those I use) and if you managed to solve your problem with it, then great, don’t lose your time with people telling you your language is bad.
I use other languages, I’m not a PHP integrist or crazy fanboy but if, by using PHP, I can create my websites, my web apps and other projects without too much hassle, then it’s good for me.