Why do people love to hate PHP?
11 comments
I think you nailed the answer to the question. Many people are going to come in and answer a different question (why PHP kinda sucks), while willfully ignoring that you can make pretty reasonable arguments about why any language/framework/environment kinda sucks. PHP seems to get a special amount of hate because to most of us PHP coder means newb because that's what we were when we wrote PHP.
It's main strength is as a server-side rendering language, with everything else bolted on. That's fine if your requirements are simple. It's not really practical to make that work side-by-side with mobile clients. Developers are finding languages that provide asynchronous (node) or concurrent (golang) features to be more important when you're mapping data from many different sources to json output.
It's worth noting that Ruby and Python don't really provide those things either, but have much better reputations as back-end languages. I don't think that will last though. I can easily picture a world where people say, "LOL Ruby! That's what we used in boot camp!"
It's main strength is as a server-side rendering language, with everything else bolted on. That's fine if your requirements are simple. It's not really practical to make that work side-by-side with mobile clients. Developers are finding languages that provide asynchronous (node) or concurrent (golang) features to be more important when you're mapping data from many different sources to json output.
It's worth noting that Ruby and Python don't really provide those things either, but have much better reputations as back-end languages. I don't think that will last though. I can easily picture a world where people say, "LOL Ruby! That's what we used in boot camp!"
I only started using PHP this year (legacy project at work), and I also strongly dislike PHP.
What I dislike about (server-side) PHP:
- Ugly syntax. For the languages with algol-inspired syntax, I feel PHP has the most oddities: "$", "=>", foreach (collection as iterator), etc.
- Inconsistency in the standard library. Naming - does the function I want have an underscore or not? isset doesn't, is_array does. The ordering of function arguments is also often different from one function to the next. IDE or php.net can help you with this, but when you're in a productive flow, this is an unnecessary impediment.
- Doing OOP in PHP, you get a lot of the verbosity of a language like Java without the type safety or standard library features. Nested arrays are common because there is a distinct lack of useful data structures in the language. Arrays are used as a mishmash of array/linked list/hash map because the language doesn't differentiate, leading to subtle bugs.
- As a dynamic language, I feel it compares unfavorably to Python in just about every meaningful way. Much more verbose than Python (list, generator and dictionary comprehensions, for example, cut down on a lot of boilerplate in Python.) Less powerful metaprogramming (in Python you can override __setattr__ to execute code whenever attributes are set; in PHP you can define __set magic attribute which doesn't work on public attributes, limiting its usefulness.) The standard library is less useful. It's not as simple to package and deploy.
- Modern features are starting to creep into in the language, but I feel it's too little too late. We recently had to upgrade a server to PHP 5.5 because I sold decision makers that using generators to stream data would result in much more maintainable code than shoehorning what we were trying to do into iterators. For a moderately large company with enough legacy, upgrading the PHP version can be an ordeal. Python has featured generators since 2003.
- I do feel that quality of candidates is an important consideration. A lot of people cut their teeth on "HTML, CSS and PHP" before moving up to "real" programming languages. The rate of applicants who don't have strong programming ability will be higher for PHP than for comparable languages.
I've been using PHP professionally for almost a year and I would never use it for a project unless it was already in use.
What I dislike about (server-side) PHP:
- Ugly syntax. For the languages with algol-inspired syntax, I feel PHP has the most oddities: "$", "=>", foreach (collection as iterator), etc.
- Inconsistency in the standard library. Naming - does the function I want have an underscore or not? isset doesn't, is_array does. The ordering of function arguments is also often different from one function to the next. IDE or php.net can help you with this, but when you're in a productive flow, this is an unnecessary impediment.
- Doing OOP in PHP, you get a lot of the verbosity of a language like Java without the type safety or standard library features. Nested arrays are common because there is a distinct lack of useful data structures in the language. Arrays are used as a mishmash of array/linked list/hash map because the language doesn't differentiate, leading to subtle bugs.
- As a dynamic language, I feel it compares unfavorably to Python in just about every meaningful way. Much more verbose than Python (list, generator and dictionary comprehensions, for example, cut down on a lot of boilerplate in Python.) Less powerful metaprogramming (in Python you can override __setattr__ to execute code whenever attributes are set; in PHP you can define __set magic attribute which doesn't work on public attributes, limiting its usefulness.) The standard library is less useful. It's not as simple to package and deploy.
- Modern features are starting to creep into in the language, but I feel it's too little too late. We recently had to upgrade a server to PHP 5.5 because I sold decision makers that using generators to stream data would result in much more maintainable code than shoehorning what we were trying to do into iterators. For a moderately large company with enough legacy, upgrading the PHP version can be an ordeal. Python has featured generators since 2003.
- I do feel that quality of candidates is an important consideration. A lot of people cut their teeth on "HTML, CSS and PHP" before moving up to "real" programming languages. The rate of applicants who don't have strong programming ability will be higher for PHP than for comparable languages.
I've been using PHP professionally for almost a year and I would never use it for a project unless it was already in use.
"There are only two kinds of programming languages: those people always bitch about and those nobody uses."
-- Bjarne StroustrupIt's an awkward, haphazardly designed, weirdly implemented and frankly ugly beast of a language which just happens to be better suited to its task (server-side HTML templating) than other more beautiful and elegant languages, none of which are hated by anyone.
Have you actually read php-src? In my opinion there are many clever design patterns used to create the language.
The implementation being clever in parts does nothing for the language itself.
What you just said makes absolutely no sense.
Perhaps you misunderstand his comment? You might write an elegant and clever Lisp implementation of Brainfuck. That doesn't make Brainfuck an elegant or clever language to program in.
Making the implementation faster would most certainly benefit the language itself. There is a logical fallacy in his statement and I was just making that clear for the record.
The design of a language and the performance of programs written in that language are fairly separate issues. Of course they combine to create the overall value of PHP, but it's like... To use an auto analogy... imagine a really uncomfortable car with no cup holders that has amazing transmission performance.
When I say 'the language itself' I mean the interface as presented to a programmer, not a sysadmin.
"It's an awkward, haphazardly designed, weirdly implemented and frankly ugly beast of a language"
You should have stopped there. :-)
Viva Scala!
You should have stopped there. :-)
Viva Scala!
Well, I suspect part of the reason some people hate it so much is also that so many other people don't. It feels somehow unjust that such an ugly language basically took over the web.
But then again, what was the other option, Perl? Evolution picks a direction and runs with it.
But then again, what was the other option, Perl? Evolution picks a direction and runs with it.
PHP's "standard library" is mostly just a collection of other open source C libraries and exposed the C API with very little transformation. For example, people point to the mysql_real_escape_string() function as an example of bad PHP design but that function comes straight from the MySQL C API[1].
Early PHP was really just a scripting language interface to C and the Web. And from that it evolved very quickly picking up all kinds of technologies along the way.
[1] http://dev.mysql.com/doc/refman/5.1/en/mysql-real-escape-str...
Early PHP was really just a scripting language interface to C and the Web. And from that it evolved very quickly picking up all kinds of technologies along the way.
[1] http://dev.mysql.com/doc/refman/5.1/en/mysql-real-escape-str...
"It feels somehow unjust that such an ugly language basically took over the web."
That's not really right, though. There are a ton of languages fighting for the server side web development crown.
I'd argue that if you limit it to LAMP, Python is a lot nicer than PHP.
Regardless, my current vote is for Scala world domination. Let the haters hate. :-)
That's not really right, though. There are a ton of languages fighting for the server side web development crown.
I'd argue that if you limit it to LAMP, Python is a lot nicer than PHP.
Regardless, my current vote is for Scala world domination. Let the haters hate. :-)
I work with PHP. My suspicion is that it's the the Java of the day. I remember a lot of crap being heaped onto Java 15 years ago and now it's PHP's turn to sit on the seat of scorn.
I feel like PHP is just a very dull work horse with a lot of legacy code devs have to churn through. It doesn't really do anything new or sexy. It kind of globs features from other popular languages long after those features have been tried and tested.
I feel like PHP is just a very dull work horse with a lot of legacy code devs have to churn through. It doesn't really do anything new or sexy. It kind of globs features from other popular languages long after those features have been tried and tested.
I just started my first job and I had applied for a role of android developer. The first I was told that I had to work on PHP. I'm currently working with PHP and Symfony 2. I have to create a campaign manager and make it compatible with the existing backend stack. I have just started to learn PHP and I don't think I have the patience to go through with it. Advice appreciated.
Because of a lot of beginners use it, and a lot of people laughed at eevee's "fractal of bad design" rant from nearly 3 years ago, and most peoples' understanding of PHP is as old as the minimum version supported by WordPress :|
"Hate" is a bit strong - as if PHP was some malignant force of the universe. I agree with Bjarne Stroustrup quote:
"There are only two kinds of programming languages: the new hotness (node, etc), and oldskool PHP"
"There are only two kinds of programming languages: the new hotness (node, etc), and oldskool PHP"
Some people like it to feel superior and some parts of PHP make an easy target. Not to mention sheer mass of PHP scripts that make a huge target.
Everyone wrote a bunch of total crap in php when they were 12, thus the deep mental links between PHP and piles of shit.
search wtf php
Many of us have contempt for earlier versions of ourselves.
Many of us started on PHP, hacking together wordpress and joomla and drupal sites, etc. We cut our teeth on it. We went from incompetent to competent on it. But then we decided we wanted to be something bigger, something better, something more professional. So we jumped on the flavor of the month (a few years ago it was RoR, now it's Node, soon it'll be Golang) and we never looked back. Since this hot-new-thing looked and acted and felt nothing like the old thing, we figured the new thing was good, and therefore the old thing was bad.
Now the new junior programmers remind us of our old selves. We've got no patience for it. It makes us uncomfortable to think that we were ever that new, ever that unseasoned or naive. They're using PHP? Oh well that only reinforces that I'm above it now. In this way our disdain for PHP is only a self-congratulatory indulgence. We're patting ourselves on the back for making that choice to leave it behind.
Like the bullies in the hallway at school, we're just a bunch of insecure people. And that's why we keep shoving PHP into a locker.