PHP has been hated for decades, and whether it deserves it or not.
What’s going on, guys? In this article, we’re going to talk about PHP and whether it sucks or not. And why developers hate It.
Now, stop right there. I know you’re about to click away because nobody cares about PHP, and you don’t either. But you should. Maybe. It might just be the most important thing you ever learn. No, probably not. But it is kind of important, and it’s worth spending a couple of minutes hearing what I’ve got to say about it.
The Hate for PHP
PHP has been hated for decades. I mean, decades. I’ve been around a long time, and I can’t remember a time when somebody wasn’t complaining about PHP being absolutely terrible. But is it? That’s what we’re going to talk about in this article.
Why Does Everybody Hate PHP?
The fact of the matter is PHP is incredibly easy to use, and it’s very quick to use. There’s nothing to install, there’s nothing to configure. Every single cheap web hosting account out there has PHP already installed. And if you have a more expensive hosting solution like Heroku or AWS or whatever, it’s very easy to get PHP up and running on those as well.
If you’ve got a cheap web hosting account for like $10 a month — and let’s face it, unless you’ve got a website with hundreds of thousands of users, a $10-a-month hosting account is probably enough to get you started — if you’ve got one of those accounts, it has PHP on it. All you have to do is upload a file called index.php or whatever.php, type a little PHP code into there, and it will just work.
That’s opposed to every other web framework like Django, like Flask, like Ruby on Rails, like Node.js, where you have to learn two things: the programming language and the web framework. So you have to learn Python and Django, you have to learn Python and Flask, you have to learn Ruby and Ruby on Rails, you have to learn JavaScript and Node.js, and on.
With PHP, there is no framework to learn. Now, I know there are many PHP frameworks, and yes, you can use one. Because you don’t have to. It just works without it.
So that makes it incredibly easy to get up and running very quickly for small startups, individuals, people with not a lot of experience or coding skills. And that’s fantastic. But it’s also the reason why people hate PHP so much. And I’ll explain.
The Story of Billy and PHP
There’s a story that’s been going around for decades. I’ve heard it at least a dozen times in a dozen different ways, and I’m going to tell you the story today.
The Beginning
There’s a company. They hire an intern named Billy. And Billy’s sitting around without much to do because he’s an intern, and the company doesn’t really know what to do with him. So he’s just kind of watching.
Over the days, he notices that the company has a really weird inventory system. It’s mostly just a half dozen to a dozen Excel spreadsheets scattered all over the place. And anytime somebody wants to do anything with inventory, they need to pull up a specific spreadsheet, fill it out. It’s a hassle. Then at the end of the month, two or three people have to compile these spreadsheets and create all these reports. It takes two or three days every month just to do it, and it’s a mess.
Billy thinks, why don’t they have a centralized database for this and some little web interface to take care of all this stuff for them? So he starts to build it.
Billy’s PHP Solution
Now, Billy doesn’t know what he’s doing. He’s not really a coder. But he’s watched a few PHP videos, and he knows enough to be dangerous. So he starts building this thing out — little database, little web interface, starts punching all this stuff together, creates a couple of reports where you press a button at the end of the month, and it does its stuff internally and spits out the report. It looks pretty good.
So he shows it to his boss, and his boss is ecstatic.
“This is great! We’ve been needing this for years! Thank you so much, Billy! But can you add this, this, and this report as well?”
Billy says, “No problem.”
Pulls up his code. His code’s four or five pages. It’s not bad. It’s kind of messy, it’s not really indented correctly because he doesn’t know what he’s doing, it’s all single-spaced, it’s a little hard to read, there are no comments at all. But Billy can read it because he just wrote it.
So he starts to modify it. He starts to add this, this, and this report. Shows it to the boss.
“Fantastic! Thank you, Billy. That’s great!”
The Growth and the Problem
A couple of months go by, and they use this thing, and it works fine. But then somebody else says, “You know what? We really need this and this report. And while you’re at it, this other report too.”
Billy says, “No problem.”
He starts coding. His code turns from five or six pages to nine or ten pages. But it’s fine. He knows what he’s doing.
Another department hears about it. They say, “Hey, can we get in on this action?”
Billy says, “No problem.”
Now his code’s like 20, 25, maybe 30 pages. It’s getting harder to read.
Another couple of weeks go by, they ask for a few more reports to be added. Suddenly, it’s 40 or 50 pages of code.
Billy Moves On
Billy realizes he did a pretty good job. His bosses are thrilled. He puts it on his resume. In 30 seconds, he gets a half dozen job offers from other companies for double or even triple what he’s making as an intern.
Billy takes off.
A year goes by. The company hears from their manufacturer:
“We’re updating our inventory codes. Just letting you know.”
Company freaks out.
“Uh oh, Billy’s system isn’t gonna work with all these new codes. We need to update it. Bob, you’re our senior programmer, have at it.”
Bob opens Billy’s code. It’s 40 pages. No comments. He throws up a little bit inside.
Bob shakes his head and goes, “PHP…”
Does PHP Suck?
Bob thinks so. And all the other real programmers out there think so. Because they get code from people who don’t really know what they’re doing.
But PHP is just a tool. Like a hammer. If you hit someone over the head with a hammer, you’re an idiot. It’s not the hammer’s fault.
Conclusion: PHP Still Has Its Place
There is no doubt Python is a better programming language. Ruby is better. Even JavaScript is probably better. But PHP is still decent. If you’ve got an idea and want to crank something out with PHP over a weekend, you can.
Don’t just discount PHP because you heard someone say it sucks. It’s probably Bob. That’s all for this article. I’ll write you the next article. And PHP isn’t that bad.
Thanks for reading to the end — you’re awesome! 🙌
Let’s grow, learn, and build amazing things together! 🚀
Don’t forget to like, save it to your list, and follow me.
This article was originally published on Medium by me.
Here is the link!
Why Developers hate PHP
Stay connected with me on my other platforms:
Top comments (49)
Nice post, but maybe you should rather bash JavaScript, which is worse in many regards Even if we write TypeScript, we must deploy code in an unsafe legacy language. Backend developers have a choice at least, not only between languages, but also to write clean code if the language supports it, and PHP 8 does. And PHP 7 did as well.
Yes, you are right!
I have shown the pretty good side of PHP as myself am a WordPress Developer.
Thanks for reading!
JavaScript isn't any less safe than TypeScript. They're the same language, one just has some extra annotations so you can run your code through a type checker and get some extra tests to catch possible mistake.
The situation where the browsers are restricted to one language and it needs to remain backwards compatible is annoying, yes. But JavaScript does a relatively decent job at being the best possible language within those constraints.
PHP does not have that excuse. It's just mediocre because it wants to.
I just wanted to send this message to the community that, why developers hate PHP because it is still a language, and didn't deserve the hate. Billy and Bob is just a story on hate on PHP, other than that you can see I did not bash, instead I presented a pretty good side of PHP and it didn't deserve hate.
Hope you all understand.
Hi Muhammad, developers here in dev.to are uh... very passionate about about PHP. When I saw your post yesterday I was like "oh no! he opened the Pandora box, maybe it'll be different this time 😰", unfortunately it wasn't. There are some thoughtful comments and others not so much, you don't have to engage right now (or ever) with any of them.
But you're right! Your post doesn't deserve hate but it did garner a lot of attention! I suggest taking this as a learning opportunity (or take it as a blog milestone! 😂), enjoy the engagement and I hope this doesn't stop you from posting here ✨
Good luck!!
I also think that a lot of PHP hate comes from the code inexperienced people produce, and I think I even mentioned that in some other comment a few months ago.
But there's also many reasons to dislike the language itself. The classic "Unexpected
T_PAAMAYIM_NEKUDOTAYIM
" is a great example. phpsadness.com lists plenty more examples of very questionable design choices that make the language hard to like.Blaming it entirely on bad code from inexperienced devs is still missing part of the picture.
The reason you have to write this comment shows that there is something wrong with the content of your post.
In my second comment I wanted to show you some examples. I shouldn't have written the first comment because it was a just a remark about Wordpress that had nothing to do with the post.
Just a quick comment, 40 pages of code is nothing. If a senior developer can't understand 40 pages of code by an intern, something is wrong with the senior developer.
Using AI tools to document is pretty amazing, and it will be accurate. Unlike comments which often say what you think the code does and rarely are kept up to date.
Perhaps the moral to the story is senior developers who can't read and modify other people's code.
Yes,PHP can let you write awful code. And English can let you write comments that aren't worth reading. :) With great flexibility comes more responsiblty, perhaps having an intern write your inventory system without oversight is a bad idea...
Seriously, first versions, especially when so small, are often scrapped. There is no reason not to use it as a prototype and do something better since it was useful.
Can't or won't?
If I have a function that leads to another function that leads to another function and I have a stack of 40 functions each with 1 different input and output, I COULD figure out what these do given time.
But the question rises : "WHY THE HELL WOULD I DO THAT?!"
so that your function isn't one giant function that illegible? same reason we break create functions for basic tasks and not make it an eye source for any new readers
My question is pending, you big meanie.
Being able to read code doesn't mean you won't hate it.
I've had to work through some truly horrific code, and it's not enjoyable at all. You find yourself looking at a line, thinking it doesn't do anything at all, but double-guessing yourself because "it has to be there for a reason, right?" Then you remove it the program still runs.
This is slow, unenjoyable and you spend the entire time remembering all the other stuff you could be doing instead if only this code was at least somewhat decent.
An hour later, you're done with a task that could have taken 10 minutes and probably refactored some of the code while you had the file open, on top of feeding it through a linter to make it readable in the first place.
What you're left with is frustration. You feel like your time was wasted.
frankly, i've read some very beautifully thought out php code before. php works out the gate, which makes most people not work on improving the code since it works on their first merry go round. as for commenting, php lets you move quickly and without much friction so i find most people just choose to keep writing the next line of code instead of stopping to add a comment. when i write in c, it's a lot slower and i leave comments between pauses of thought.
What's wrong with PHP? Nothing :-) but maybe there's something wrong with the way it's often being used ...
People who use a framework like Laravel don't hate PHP, they love it! Especially newer versions (PHP 8), which have added a lot of performance, and some cool features ...
Yes, if you see WordPress code it tends to be "stone age" and terrible, but there's a lot of love for Laravel, and I think that has also made people reconsider their views of PHP.
In other words - any programming language can be used in a cool way, or in a terrible way ;-)
Maybe you should look at Wordpress before you judge the language.
Any code in any language can work without a framework. It are the developers at Wordpress who choose not to use a framework. The problem Is they also choose to support a language version that is unsupported for over two years now.
And that is why you are missing out on great features.
php.net/releases/8.0/en.php
php.net/releases/8.1/en.php
php.net/releases/8.2/en.php
php.net/releases/8.3/en.php
php.net/releases/8.4/en.php
Billy in your story is Wordpress. And Bob does not blame the language , but Billy.
Thanks for your opinion, much appreciated.
It is not an opinion. I get it from the tone in your post.
This shows me you never have touched a php.ini file or installed extensions.
Any language can be picked up by people with no experience. But you still need to know how to set up a webserver if you are going to create a website.
You don't consider yourself to be a real programmer? You are a Wordpress developer.
That is not really a glowing recommendation for PHP. It is more a look I fixed a leak with duct tape vibe.
Sure, thanks for the duct tape.
People think that PHP is bad because they don't understand that language is not the problem of their sucks projects and architecture
Thank you, I read your article to the end.
This title is better for your article: "Why we need to use PHP frameworks"
Of course, I must say that you can still write good programs in PHP without using a framework.
If you put some talent and creativity:
At Elanat, we are trying to make WebForms Core technology available for all programming languages.
Installing tools for many programming languages was complicated and difficult, but for PHP we just installed EasyPHP.
WebForms.php Update to WebFormsJS 1.6
Sorry, but I think that PHP has several intrinsic defects and Billy is not to be blamed for them. Sure a tool, like a knife, but a tool can be a bad tool, like a rusty knife.
Some of the issues I find in PHP
implode
the separator is the first or the second argument?)implode
exchanged the order of arguments in PHP 8.0.0. That's sadism ;-) I do not want imagine the mess in using an old code with the new version...===
it is a bad sign: it usually means that the language converts everything and the equality is not transitive (Ruby is an exception to this since Ruby is is not an "hard core converter" and gives to === a different meaning).Those defects are not fatal, mind you, you can still write very large and complex software and you can have a smoothly working code if you are careful. The problem is that if is a big if: programmers are human being and they can be tired, worried, sick and make mistakes. A good language is a language that protects you from silly errors that you'll inevitably do, even if you are a seasoned professional.
Languages like JS and PHP give you lots of freedom, no need to declare variables, no need to worry about the type of your data, ... but this freedom makes it easier for error to sneak into the code.
Personally, give me a static and strongly typed language, possibly with contracts, a language that can act as a pair programming partner.
True, PHP has issues. But the language improves with each new version.
Php 8.0 has a saner number comparison.
Type hinting is in my opinion on par with strongly typed languages.
Sure you still can do all that bad stuff, but if you add a static analyser, like phpstan, to your development flow you will be yelled at.
You can make the checks as strict as you want and even create your own. I think that is better than a compiler.
and in asm the destination and source can swap places depending on what syntax you use as well as what version of it you use, so would you call that a bad language?
I respectfully disagree with your assessment of PHP. The language has significantly improved with versions 7 and 8, introducing strict typing for enhanced code reliability. Its flexibility allows efficient coding, and performance has been boosted by the Just-In-Time (JIT) compiler in PHP 8. As of 2024, PHP powers over 75% of websites, highlighting its robustness in web development.
The PHP Framework Interoperability Group (PHP-FIG) has established standards, known as PHP Standard Recommendations (PSRs), to promote consistency and interoperability among PHP projects. These standards cover various aspects of PHP development, including autoloading (PSR-4), coding style (PSR-12), and common interfaces for logging (PSR-3) and caching (PSR-6). Adopting these standards fosters a unified and professional PHP ecosystem, enabling developers to create maintainable and robust applications.
Additionally, the PHP community benefits from Packagist, the default package repository for Composer, PHP's dependency manager. Packagist aggregates public PHP packages, simplifying the discovery and integration of libraries into projects. This extensive repository streamlines package management and encourages code reuse, enhancing PHP's efficiency and appeal in the development community. With tools like Composer and Packagist, developers can rapidly spin up applications by easily managing and incorporating dependencies, thereby accelerating the development process.
Furthermore, PHP-FIG standards, such as PSR-12, provide a comprehensive coding style guide that ensures code is neat and consistent across different projects. By adhering to these guidelines, developers reduce cognitive friction when collaborating, as the codebase follows a uniform structure and style. This uniformity not only makes the code more readable but also simplifies maintenance and reduces the likelihood of errors. The emphasis on consistent indentation, spacing, and naming conventions contributes to a cleaner and more professional codebase, facilitating better teamwork and code quality.
While I agree with most of your comment.
Sadly the biggest part of 75% of the websites are Wordpress sites. Which is not the best student in the class.
So the likelihood that people are going to see that code is bigger than they are going to see standards driven projects.
No PHP blaming from my side. It is a tool, and how you use it.
For the story, I would turn the table: the one to blame in this case it's the company. It let the intern do whatever he wanted, and as he got something they let him do whatever he wanted without a
Bobmentor. Bob on the other side spend too much time with this environment, so he would never blame that environment first without understanding its circumstances.All in all, Bob should be thankful to the young developer. Now he has a strong argument to refactor the code or bring in a new tool, as the old one doesn't fit the requirements anymore. Win-Win situation for everyone.
Try to find the jokes here. 😁
Some comments may only be visible to logged-in visitors. Sign in to view all comments.