Why some people hate PHP

Posted: 2012-12-02
Category: PHP
Tagged: php

This is a repost of my answer to the Quora question: Do a large majority of people hate PHP solely because other people do so?

There are a lot of reasons people "hate" PHP, or at least look down on it. Some of them are founded, some are not, and some of them are circumstantial.

1.) "Inconsistent haystack / needle"

You hear a lot of people banging on about inconsistent haystack needle, but this can be read with a single rule:

array: needle, haystack
string: haystack, needle

It's as simple as that, but people often forget and assume its more complicated.

Reference

2.) PHP is a HTML file, with logic

PHP assumes the file will be HTML first, which can lead to some stupid output problems where whitespace sneaks in before or after those tags. There are some plans to change that, but it can lead to trouble and reminds everyone that PHP has a history of "templating first, programming later".

New File Type for Pure-Code PHP Scripts

3.) No standards

There are a million frameworks with a million standards, people fight over snake_case v camelCase and have no clear plans as to what is correct. That means people coming from Ruby to PHP (say they have to build a PHP library for a REST API they just built) they have no idea what to do. I've seen this problem a lot, but the PHP-FIG (Previously known as the PHP Standards Group) is working on that.

PHP-FIG
Google Group

4.) Lack of Quality Packages

NPM, Bundler/Gems, PIP, CPAN etc all provide quality code packages for developers to plug into their code, meaning they can write less and do more. PHP does not have a consistent package system other than PEAR, which is an aging beast which most people ignore due to the low quality or old age of the packages.

PSR-0 (part of the PHP-FIG) is a standard that has been generated to help code packages work together, and Composer is a project that has been built to make NPM-style dependency handling for PHP. In time we'll see the quality increase, meaning much less bad code is going to be rebuilt time and time again by every developer - and much more time can be saved instead of developers working on fragmented "framework specific" solutions.

Packages: The way forward for PHP
Composer

5.) Misconception

I know a bunch of incredibly smart Ruby developers who used to use PHP back in the PHP 4 days, who seem to think nothing has changed. PHP 4 to 5 was a massive jump and PHP 5.2 to PHP 5.3 was another HUGE leap forward (after-all, PHP 5.3 was meant to be PHP 6 but they back-ported every feature other than Unicode which was not going to work).

The fact that they go around telling all their Ruby friends that PHP has no "method_missing" (we do, it's called __call()) and complain about other things that no longer exist, or have been improved, or added, means that a lot of people who laugh about PHP are laughing about a 7 year old version of PHP. Somebody said PHP was terrible for not having a built in server like Ruby... well it does.

PHP Built in Webserver

6.) You were doing it wrong

"You can mix MySQL, HTML and PHP in the same files. PHP is disgusting!"

I've said the same about ColdFusion and had it politely explained to me that I was just doing it wrong. This is a good point. Just because a language is flexible enough to let you do whatever you want does not make it bad.

The structure comes from a framework. I don't know many people using Ruby who aren't using Sinatra or Rails, and I don't know many Node guys who don't use Express, CanJS, etc.

7.) Elitism

Not using PHP is cool. Who wants to use the same language you used when you first started writing code as a kid? Who wants to use something that has loads of terrible script kiddies using it? It must not be a challenge, it's not smart enough for a smart programmer like you.

You need something that will challenge you and anyone using PHP is just not smart enough to learn something else...

I hate that point of view so much. In the lift today on the way in, my colleaue overheard a conversation from two total strangers: "You can't trust these PHP shops, why don't they learn a real language?". This covers a lot of the views of people around, and if it's not elitist then it is at least short sighted.

So, why do people still use PHP?

If nothing else; Momentum

The latest stats from the W3Techs show that almost 78% of the top million sites are built with PHP. Now, while you can sniff at the quality of the language itself you can't sniff at that.

http://w3techs.com/technologies/overview/programming_language/all

I am proficient in PHP, Ruby, Python and have dabbled with NodeJS. Why am I  using PHP? Because it has the biggest market.

Lots of developers want to chase "the perfect language", "the perfect IDE", "the perfect hosting platform". The answer is that there is no perfect tool, just options. Nobody should be "hating" any of them.

Comments

Gravatar
Cwspear

2012-12-02

I think #6 is my favorite. I read posts where people compare straight up PHP to Ruby on Rails. It's like some people don't realize there is just plain Ruby. It's not comparing apples with apples. You should be comparing popular PHP frameworks with RoR.

I also think PHP is popular because of the much lower barrier to entry. Yes, I started with PHP, and yes, I know other languages, but I like to be really good at one, and there is a lot of PHP out there, and it is not going anywhere soon.

Gravatar
Nerdklers

2012-12-03

Excellent stuff Phil. What I find interesting is that PHP developers in general don't hate other languages, they tend to emphasize their strengths and use them when appropriate.

Haters gonna hate :)

Gravatar
Jonatan

2012-12-03

I hate you!

Just kidding....

Gravatar
Christian

2012-12-03

I AM a php developer and a couple things certainly come to mind in regards to my quibbles with the language:

1) Fragmented community
Though this will probably get better, the number of disparate packages/solutions (think frameworks) is frankly obnoxious; while Ruby's RoR and Python's Django receive the support of an entire community, we like/love to herald the next reinvention of the wheel (I am looking at you Laravel) and as a result we literally have HUNDREDS of mvc frameworks that all do esseentially the same thing.

2) Weak or non-existent meta-programming facilities.
This is something I wouldn't have complained about two or three years ago, but my exposure to Ruby + attempting to write persistent/stateful application servers in PHP has thoroughly changed my mind; I would literally KILL to build/redefine constructs at runtime, but PHP (a godamn interpreted/dynamically typed language), is still too thoroughly in bed with Java in terms of culture (as in it will never, ever happen). We're given things like traits, which i personally find useless outside of the few suspect uses (logging..), when all I really want to do is change a method behavior or attach a callback to a method invocation at runtime (and without having to build/attach a callback system).

3) Where are the cutting edge ideas?
The PHP community is full of developers whom are beginners, quasi ui engineers and/or are not classically trained. As a result, most of the aggregate blogs and material I see are both dedicated toward simple ideas and that have already been addressed ad naseum. PHPMaster, which admittedly I don't like, has an article on sending emails with Swift.. compare this to rubyflow and you'll get an idea of the differing levels of sophistication between the two communities.

Gravatar
Ed

2012-12-04

I've been using PHP since high school but I started with Perl and went with PHP. I agree people who don't know better are the worst. Case and point I worked at a .NET company and one guy always griped about PHP and when I asked him which version he's talking about, he said PHP 4, which he last touched in 2001. I told him it made leaps and bounds today, but he disagreed, its just how some people think.

I'll admit I love PHP but I can hate it too. Just like there's things I loved about .NET but other things make me want to scream. I honestly think you should keep an open mind, each language is just a tool, don't make it any bigger than that.

Gravatar

2012-12-04

Sorry Christian but I disagree with everything you just.

1.) There are a few things wrong with this statement. There are not litterally hundreds, there are about 50 to speak of, and only about 10 of them are active. Maybe 15, tops.

I also disagree with the fact that this is a bad thing.

Why does Kohana exist? Because it can do a bunch of things CodeIgniter can't do. FuelPHP build on top of what they had both done and Laravel are doing the same. These are all a similar family of frameworks that share a similar philosphy, but aim at different versions of PHP - meaning they are for different users in different circumstances.

Also, have you ever had a look into how many JavaScript frameworks there are?

I would MUCH rather avoid the Ruby / Python situation where there are only 2 or 3 main frameworks. Each framework has a very different way of thinking, and personal I detest some, and find others too complicated, while others are too simple. We have a huge range of developers in the PHP community and we need a range of frameworks to reflect that.

2.) A constant is supposed to be constant, if you want to redefine shit on the fly then you're absolutely doing it wrong.

3.) I'll agree that there is a lot of basic shit articles around. Most of the learning materials for PHP developers is outdated or written by people that don't know all that much. I disagree that this shows the different levels of sophistication between the two communities, I'd just say that we have a LOT more begginers in the community which often learn how to tie their shoes then shout about it. We also have plenty of extremely smart developers doing a lot of extremely clever things. I could give examples of this all day, but the first to mind is this: http://socketo.me/

Gravatar
Max Toro

2012-12-04

Hating a technology is stupid. I don't hate PHP, but I would never, ever choose it. And about your "big market" argument, that's a down side in my view, more people writing PHP getting paid less. Of course, if you are good at something you'll always find good work.

Gravatar
Christian

2012-12-04

"A constant is supposed to be constant, if you want to redefine shit on the fly then you're absolutely doing it wrong."

What are you talking about dude? I wasn't referring to constants, I was referring to the (lack of) available facilities that allow for building/manipulating programming constructs at runtime (ala metaprogramming); all of which fits the paradigm of a dynamically typed language. Unfortunately, PHP is a dynamically/weakly typed language that wants soooo badly to be the opposite (static/strong typed).

Btw, if you think that meta-programming has no place in your toolbox, then you're "absolutely doing it wrong" ya cheeky bastard :) Phil, I admire your outspokenness in the community, but stop being such a cheerleader.

Gravatar

2012-12-05

Hey Max: I would never normally answer a conversation with this, but... I make a fucking lot of money though PHP consulting. If you want to mention numbers, I will probably win at numbers.

Hey Christian: metaprogramming is not what PHP is about. My dayjob uses erlang, java, python and perl. Why do you think one language should do EVERYthing? I can put all of my clothes onto the same wash... just saying.

Gravatar
Boabramah Ernest

2012-12-05

Thanks phil for the http://socketo.me link. That is really interesting.

Gravatar
Christian

2012-12-05

Yes (it is not what PHP is about), but it teases/tantalizes the prospect, giving us method_missing/__call functionality (which imho is the major component of metaprogramming), yet stops just short of the full monty. I am not asking for everything-is-an-object, or garbage collection in objc iphone applications or reflection in c++.. I am simply asking for what is well within the means of a language that frankly refuses to do so because it doesn't fit within its "cultural alignment". You talk about outdated misconceptions in regards to the evolution of the language (which I agree as I have heard it countless times in the last ten years), well PHP has evolved to a point that it doesnt (shouldn't) have to follow the Java model. I am not referring to the expressive vs concise balance (if anything, I always prefer expressive/idiomatic code to a concise nightmare to read - which is why Ruby, to me, is joy to work with, compared to Python/Perl), but to the fact that if we are working with a dynamic/weak typed language, then we should enjoy the godamn fruits of that paradigm. I don't know about you, but something as fucking simple as named parameter support would give me a hardon.

To keep with your analogy, I am not trying to put all of my clothes in the same wash.. I'd much prefer to use a laundry service so I do have worry about folding shit. Given that were (ny) neighbors, I am guessing you do the same homeboy.



Ha - given that we're neighbors (NY), I'd guess you prefer a laundry service to

Gravatar
Matt

2012-12-05

I dislike writing in PHP for two main reasons:

1) The syntax is verbose and ugly. I felt that way even when I was primarily writing in Perl but now with Ruby and Python it really feels like a slog to write things in PHP.

2) While new features have been added they don't seem to have very quick uptake in the community. Even today OOP is still seriously underused. This extends even into the core libraries, which one would normally expect to be the first to take advantage of new features. Why are array and string operations still all free functions instead of being methods?

There are some other more minor reasons as well (can we please just assume <?php now?) but overall I just don't see a compelling reason to use PHP instead of Ruby or Python.

Gravatar
Timothy J Warren

2012-12-05

Christian: There's plenty of meta_programming functionality in php.

You can call arbitrary functions, methods with arbitrary parameters, dynamically create variables, dynamically create new constants, and lookup constants by name.

You can dynamically create methods with the __call function, add/get class variables with __get and __set.

What kind of metaprogramming features are you looking for?

Gravatar
Watts

2012-12-06

As one of the folks who put up a briefly infamous anti-PHP rant a while ago, I think I'd add a corollary to #6: "You were on a project that was doing it wrong." The catalyst for that particular rant of mine was a Symfony 1.x project that the original developer had essentially built his own secondary framework over, so even if you knew the canonical Symfony way to do something it didn't work. A new developer had decided to port it to Symfony 2, which created a lot of new headaches, not all of which are Symfony's fault. (I really don't like Symfony's rather Java-esque Every/Thing/IsA/Class/Ten/Levels/Deep.php source code layout style, though.)

PHP shares with Visual Basic the property of not only being really easy to get going in, but largely being marketed to people who want to hack a project together quickly. Is this PHP's fault? I don't know, really; it's true that you can absolutely do good code with PHP (and that the 5.3+ features help immensely), but I can't help but suspect the "get things hacked together" mindset has affected the language over the years to some degree. PHP lets you do things like Laravel, but on the flip side, I'm pretty sure that Python and Ruby would make it much more difficult than PHP does for a naive programmer to essentially reinvent the concept of objects using global variables, and there really is some value in making people avoid "solutions" like that.

And sadly, I am not making that example up. It's what the current codebase I'm working with does.

I should note, though, that I don't *really* hate PHP. I took my current full-time position working with PHP after I wrote that rant.

...but I still dream of being able to rewrite the codebase someday using ACTUAL DAMN OBJECTS.

(*ahem* I'm better now.)

Gravatar
Pete Hawkins

2012-12-06

Christian, never mind PHPs magic methods, if you want to do meta programming at runtime: http://php.net/manual/en/book.reflection.php, PHP has all of the tools for the job, lest not forgot a lot of the issues in the ruby community brought up by serious overuse of meta programming.
I don't know about you, but I seriously strive for maintainable code simplifying problems and making it easy for others to work with, meta programming is always a last resort in my mind, strikes me as armature that this is your first critisim of the language.

Gravatar
Christian

2012-12-06

@Tim

Sigh.. no shit dude. Honestly this is why the PHP community irritates me - overeager, useless comments from self-styled developers with zippy background in CS

What meta functionality would I like Timothy? How about defining true, first-class static/instance methods at runtime? I COULD define a "ghost" method in our catch-all __call/__callstatic, but here is what the method/receiver lookup looks like: look for method signature in in current class/instance receiver; look for method in current class receiver hierarchy; look for method in current class/instance receiver __call/__callstatic method body; if called parent::__call/parent::__callstatic, look for method in current class/instance receiver hierarchy defined __call/__callstatic method body.

Besides this all being horribly inefficient, its all really for naught.. whats wrong with the picture below:

class Test {

public function __call(name, arguments) {
echo "method $name not found on instance receiver"
}

public static function __callstatic(name, arguments) {
echo "method $name not found on class receiver"
}

public function runtest() {
static::method_does_not_exist();
}
}

$t = new Test
$t->runtest();

Besides this, what else? How about method/class event hooks (e.g. a method is defined, a class is extended), or on the fly method redefinitions (monkey patches) whose change ripples down the class heirarchy (all at runtime), or method aliasing, etc etc. The people in Java land would call this heresy, but dude, if you feel that way, go write Swing applications with textmate.



Gravatar
Jonathan S. Fisher

2012-12-07

Obligatory link to "PHP is a fractal of Bad Design":

http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

Gravatar
Christian

2012-12-07

@Pete

It really irritates me when I have to repeat myself, but here it goes. "Honestly this is why the PHP community irritates me - overeager, useless comments from self-styled developers with zippy background in CS"

Dude, reflection.. really? I am not even (really) going to bother to dignify the amatEUr comment with a response, other than your a frontend developer who cut their teeth on PHP. If you're seriously going to get into objc development, I'd suggest going to coursera.org and taking a course on the fundamentals of CS theory and at least some practice in a static/strong typed language and a strong grasp of pointers (you'll love it when you master them, and then you'll realize how amazingly refreshing it is to work in ANY dynamic/weak typed language. When you get to that point, then you'll enjoy metaprogramming techniques)





Gravatar
Joshua Parker

2012-12-17

"The answer is that there is no perfect tool, just options. Nobody should be "hating" any of them."

Such a true statement!

Gravatar
Alexandr

2012-12-19

Of course PHP is far not the most beautiful language, but when somebody says that he hates some language I recall this:

"There are only two kinds of languages: the ones people complain about and the ones nobody uses"
- Bjarne Stroustrup

Gravatar
Java Dev

2013-01-16

The main reason is a weak OOP... But PHP suits as no one else for the development of small sites at short terms.

Gravatar
Juliet

2013-02-15

Do you mind if I quote a few of your articles as long as I provide credit and sources back to your weblog?
My website is in the exact same niche as yours and my visitors would definitely benefit from some of the information you
present here. Please let me know if this okay with you.
Thanks!

Posting comments after three months has been disabled.