PHP Basher Bashing

Posted: 2011-12-20
Category: PHP

Anyone who has used PHP for a while knows that it has its ugly parts. Recently I've seen a whole swathe of PHP-bashing articles and that would fine if they were they are making a valid point, but some of it has just been - as I tweeted recently - "absolute drivel".

The article I am referring to is PHP is not an acceptable COBOL by Watts Martin in which he started explaining how PHP was:

a powerful enough language to do nearly anything you want, ubiquitous, easy to get up and running (on many web hosts it’s pre-installed), and forgiving of shitty code.

I for one think that is absolutely excellent. If your employee or team-mate is writing shitty code - in any language - then discipline them, fire them or train them better, but don't blame the language for being flexible enough to allow them to complete a given task.

It started as a set of scripts written in C, but over the years has turned into a huge, shambling mutation.

I'm not sure about this at all. OOP in PHP 4 sucked. In 5.1 it was ok, 5.2 was considerably better and the logic in PHP 5.3 has allowed us on the FuelPHP development team to make some truly lovely laid out code. PHP 5.4 will bring us traits which allows us to manage multiple inheritance neatly and I'm pretty excited about that but in no way do I consider PHP to be a "shambling mess".

What nearly all other languages have in libraries PHP shoves into the language core, often in multiple incompatible ways.

Like what? There are quite a few PECL extensions kicking around and there's a whole lot of PEAR available, but what of that is in the core that shouldn't be there?

Watts entire article was full of similar statements to this with his complaints ranging from things I absolutely do not care about to things that are just not true. I toyed with the idea of writing a response at the time but in the end couldn't be bothered and put up a lazy negative tweet. To be fair this was rude and non-constructive as he pointed out in his latest article: PHP Redux.

There's a reference in there to one of the PHP Advent 2011 articles Cracks in the Foundation written by the smart Gwynne Raskind. The quote says:

Over time, PHP has suffered everything from security failures to bad design decisions. Some of these problems were avoidable, but others weren’t. […] If asked what the problem [with PHP] is today, I would say, "no design and no plan."

He missed out the sentence before that which says "Unfortunately, nothing’s perfect — PHP included.". Absolutely, there have been security issues and bugs in PHP's past like any other language. One thing I'll say here is that none of them have ever had any effect on me, developers in my network of contacts or any of the teams I have ever worked with. That's not to say that the bugs never effected anyone and I am sure people will provide random examples, but I spent a few years developing for a massive team in a financial services company with a PHP platform doing all sorts of crazy stuff and guess what? Nobody there had ever had any problems with those security bugs in that job or any of their others. PHP bugs crop up and they are fixed before the exploits are made widely available. If your host is slow to upgrade then move away from that host instead of complaining about the language - it's their job to apply security patches in a timely fashion. If you have an SLA and you get hacked then sue the host's ass off for being incompetent.

As for the "no design and no plan" that can probably be said for PHP 1-4 but I haven't used PHP 4 since I was 13 and the last decade has been just fine. We do of course have the issue with string function needle and haystack orders being impossible to remember but this is on the list of "things I just don't give a damn about". An upcoming version of PHP will some day walk in and set strings to be primitive objects, add new string methods to those objects and deprecate procedural string functions. When that happens the one and only true "PHP has evolved badly" argument will be squashed and until then I will continue to build applications and still not care.

Anything else?

Plenty! As a contributor to CodeIgniter and FuelPHP his comments about PHP frameworks really got my back up:

We've learned a lot about how to make web frameworks over the last decade, and we want to bring that to PHP. Hence, frameworks in PHP!

It's not like PHP developers are only just working out how to make toolkits now. Just to make one example:

  • Rails 1.0 - December 13, 2005
  • CodeIgniter 1.0 - February 28, 2006

CodeIgniter was never far behind Rails and it copied nothing.

But by building frameworks on what is itself a (bad) framework, instead of fixing poor design decisions from way back when, we stuff our new framework full of workarounds.

Is this not what jQuery is doing? It sits on top of JavaScript to help neater traversing of arrays, simplifies access to the DOM, replicates features that are missing in certain versions or implementations of JavaScript and gives one uniform way to handle your interaction logic across a broad range of browsers. For years people LOVED the way CodeIgniter added a compatibility layer providing PHP 4 with some of the new PHP 5 features. That may be less relevant now but it was bloody important at the time.

I've spent the day - I now suspect needlessly - setting up an Amazon EC2 instance to mirror that architect’s own dev setup, as it appeared I’d lost the wrestling match on my local machine with PEAR and PECL2 and Symfony’s own dependency management system.

I've had entire days lost to dependency hell during projects in Rails - yes I'm not a all-PHP-all-the-time zealot - and I can imagine this happening for any system that requires versioned tools. If it's not PEAR or PECL it will be CPAN, Gem, pip or whatever your language uses, don't pretend like PHP is the only system that ever struggled with dependencies. Besides by complaining about this you contradict yourself as this is the exact reason frameworks like CodeIgniter were born in the first place. By providing the developer with one set of classes in a framework they know all the classes available work with each other - no dependencies, easy deployment, one code style.

Symfony 2’s coders are doing everything as right as possible, and that’s probably true of most of the other mysterious floating bits in the gumbo our new de facto chief architect has cooked up. But we’ve still ended up with a mishmash of patterns from Django, Rails, and enterprise Java, all held together by melted licorice jellybeans.

Well in that case Watts you should probably go and have a word with Fabien Potencier with your feedback. I've heard that he quite likes Symfony - and so do quite a few others - but us framework types are always open to constructive feedback.

Done now?

Sure, I could probably go on but I feel I have justified my comments.

The main problem I see is this; when people learn a new language like Ruby or Python they notice a lot of interesting differences, cleaner syntax, funky new cloud-hosting services and they get their "nerd-on". Then they run around going on and on about how amazing it is and become a zealot, looking down their noses at people who are "still" using PHP because "us stupid PHP developers aren't smart enough to code in anything else". Thats elitist bullcrap and it has no merit.

So why do I "still" use PHP?

I use a range of tools. Sometimes Ruby in the form of Sinatra or Rails but most often it's CodeIgniter or FuelPHP. Why? Because PHP is the language of the internet right now and has been for years, and that means my applications sell more! PyroCMS is compatible with PHP 5.2 and that means a huge number of people can download, contribute to and buy my software - that makes me pretty happy. I could probably recode it in NodeJS or Closure and tell everyone how awesome I am for using a new system but then I'll get less sales, less people will be able to build addons or extend it.

Are my commercial applications the only reason I use PHP?

Despite known flaws and imperfections I continue to use PHP as my primary language because during all the time I spend worrying about which technology is the neatest, coolest or shiniest I could have built a new application to sell or finished another client site. In the words of Captain Ed Murphy in Lethal Weapon 2, "Sometimes you have to know when to say 'I don't give a fuck' or you'll give yourself a hernia.".

Comments

Gravatar
William Rufino

2011-12-20

Just great... I still can't believe people still say php is shit, because you can write shit code in it...

You can write shit code in anything... its just a matter of wanting it.

Great article man!

Gravatar
Matt Basta

2011-12-21

By "shambling mess", I think a lot of folks are referring to the standard library, or lack thereof. The "everything is a global" monstrosity is both shambling and a mess, by all standards. For any reasonable, cross-platform developer to know whether any given search function in PHP is haystack needle, needle haystack, needle replacement haystack, replacement haystack needle...the confusion goes on and on. What about naming consistency? inarray has an underscore, but natsort doesn't. htmlspecialcharsdecode doesn't follow either pattern.

This isn't something that can be fixed, though, by the language or a framework. PHP will never get rid of these inconsistencies and never-ending backwards-compatible nightmares. It's easy to get started in PHP because of it's sheer simplicity but it's virtually impossible to become a master (without becoming a little bit insane in the process).

Gravatar
Daniel Polito

2011-12-21

Congratulations for the article, agreed.

Every language has its advantages and disadvantages and yours use case indeed. I'm totally happy with PHP and i also never went affected with these issues.

Gravatar
David Gordon

2011-12-21

Props for a nicely supported rebuttal!

It seems to me that each language falls somewhere on a readable/writable continuum. PHP is extremely writable, largely because it is dynamically typed and also for many reasons specific to its design. However, I think there are some sacrifices in terms of readability that can easily get out of hand with non-descriptive code and poor organization. And while there is a lot of inexperience in the PHP user community, first of all, that's a testament to the language's accessibility, and secondly, those young nerds grow up to write borderline-poetic libraries like FuelPHP and Lithium!

Gravatar
Josh Manders

2011-12-21

Phil, you sir. Are a legend.

Gravatar
Edwin

2011-12-21

Totally agree with you. Great article.

Gravatar

2011-12-21

@Matt: "to know whether any given search function in PHP is haystack needle, needle haystack, needle replacement haystack, replacement haystack needle...the confusion goes on and on." This is an absolute non-issue. If it is a problem its trivial at best.

Any decent IDE will autocomplete those methods and if you don't have auto complete you just hit CMD+Tab, CMD+T, php.net/strpos then you have your answer.

"This isn't something that can be fixed, though, by the language or a framework. PHP will never get rid of these inconsistencies and never-ending backwards-compatible nightmares. "

They easily could. As I said in the article I'm in no rush for them to do this, they might do it in PHP 6 or 7 but I know that transitioning from proceedural functions to primitive objects for strings and integers would be easy enough. Then we go from strlen($string) to $string->length() and we're all happy.

On another note this is of course ABSOLUTELY something that can be fixed by a framework, as I could write a class tomorrow that normalised all the weird string functions and worked like this:

$foo = new Str('something');

$foo->pos('thing'); $foo->replace('thing', 'stuff');

I won't, but I could. Don't say never, cant, wont, quite so much because none of this are absolute.

Gravatar
Joffrey

2011-12-21

Great article, agreed !

Gravatar
Nikic

2011-12-21

@Phil You are taking all this too personal, I think. I have seen many PHP developers say "PHP sucks", including core developers. I've said it myself countless times. Over and over. Still, I am here, developing in PHP. After all, they are right, I am right, PHP does sucks and it sucks hard. Just like C sucks, just like Java, just like JS, just like any other popular language. The creator of C++ said "There are only two kinds of programming languages: those people always bitch about and those nobody uses" for a reason: Any popular language - and PHP is undoubtedly very popular - will naturally accumulate lots of bashing.

So really, don't take any of this too serious ;)

Gravatar

2011-12-21

Nikic: I just wanted to put my thoughts out there to all the people complaining and moaning. I didn't have tears in my eyes and I wasn't breaking a stress-ball while writing the article. I don't take it personally because I didn't write PHP, but when I get named in an article complaining about PHP I need to put an answer to that.

Just like plenty of other developers I too have said "man that's annoying" about trivial things in PHP, but then got on with my day.

Gravatar
Sirfilip

2011-12-21

To be honest i like Ruby and Python more than PHP, but that does not mean that PHP is a bad language. PHP is a great language and a feature that i like most is the autoloading feature. What i miss is extending your classes during runtime but i can live with out it. People are always forgetting that with each language comes a certain mindset that a developer should adopt. You cant ask from PHP to do what other languages do and vice versa, to learn a new language is not enough just to learn the syntax you should develop the way of thinking and problem solving in its context too. And for anyone that doubts that it is a great language just take a look at the websites built with PHP. You cant do that with a crippled language. PHP earned its place and it is the web.

Gravatar
Watts Martin

2011-12-21

It's a fine rebuttal. You put that jerk--oh, wait. Crap.

Seriously, I don't hate PHP. I'm just exasperated with it. Gwynne Raskind's article on the PHP Advent site did a perhaps better job of explicating why, since Raskind didn't come across as a total curmudgeon about it.

I think PHP is a shambling mess for similar reasons that Javascript is a shambling mess: both grew in a rather undesigned, ad hoc fashion, and while later versions have started trying to add cleaner ways to do things, the old ways stick around because they can't be removed without breaking backwards compatibility. You can write lovely PHP code and you can also write lovely Javascript code, mostly by ignoring the bad parts of the language. (I'd love to see something for PHP like "[removed] the Good Parts"; while I know there is a "PHP: the Good Parts" book, the title lies.)

One can argue, as Douglas Crockford has, that despite all the shambling parts of Javascript, the core of the language is really well-designed. Is the same true of PHP? I suspect Phil and many others would say "yes" with little hesitation; while I wouldn't unhesitatingly say "no," I'm more inclined to "reply hazy, ask again later." PHP is certainly the most successful web language, and that's nothing to be sneezed at, as some commenters noted. Of course, if you count all the applications across all the large and small businesses that have been written in various incarnations of Visual Basic over the last three decades, it's far and away the most successful programming language ever.

(As an ironic footnote, shortly after I wrote the "COBOL" post, I became involved as a volunteer programmer on a fairly large web site built on the Yii PHP framework. No, I am not telling them to switch to Python.)

Gravatar

2011-12-21

Watts: I wouldn't blindly just say "Yes the core is amazing everyone who wrote it is awesome" because I'm not an idiot. My whole point here is that while it's been trendy to bash on PHP you should have a reason for doing it. The PHP Advent talk made some good points and your post was mainly "So, there are some bits that aren't great". We know that, but what was the point of your article? "Bad things are bad"?

Applications built with PHP are only going to become a legacy nightmare if shit coders are coding them. If an application is well built in PHP it will stand the test of time, as while you are unhappy that PHP is progressing forwards I am content with the language as it is and am happy with what is on the horizon. There is not as much work to be done as you think and Zend are getting there.

Meanwhile projects like Pagoda Box and Composer are taking what we have forwards in other ways, meaning that if all we have to complain about is some historic irrelevant bugs and a weird order of string function parameters then... well we haven't really got all that much to complain about. Thats what it is at the end of the day, pointless complaining.

Gravatar
Jenna Fox

2011-12-21

I consider PHP a poor language for any sort of development for only two reasons:

1) The core language has inconsistent function naming and argument ordering, which for me at least, required a heavy dependance on the manual to figure out how to call common simple functions, as I'm not great at memorising those sorts of facts. This makes me a lot less efficient in PHP. 2) The language design itself often makes the easiest way to do a thing be a really bad way to do that thing. The problem isn't that it allows people to write terrible code - I think the same is true of Ruby - a language I adore. The trouble is just that the language in many ways seems to encourage bad code, by making it the path of least resistance. There's no doubt a sufficiently excellent developer can build good quality software in PHP. The trouble is, especially with open source, that most contributors are not that disciplined. In some other languages where the easiest solution is often the cleanest and best solution, laziness is a virtue.

I hold somewhat of a grudge against PHP because early on in my hobby-driven interest in programming, I failed to make good software design choices in larger projects, and eventually those projects became unmaintainable before even reaching usable completion. It very nearly succeeded in making me give up on trying to learn to write software - in a depressed state, I looked at Ruby, and it showed me the tools I was using were making learning and building apps more difficult than they needed to be and teaching me bad habits. I strongly believe PHP is a poor language for beginners, and remain convinced that many people who would otherwise grow to become really great software designers would give up in the face of repeated failures on difficult platforms like PHP. As teaching programming to beginners is one of my passions, this problem is very close to my heart.

Gravatar

2011-12-21

Jenna: You're basically saying that because PHP let you build crappy applications from the offset so you blame the language? Ruby has frameworks like Rails, Sinatra, Merb, Ramaze and whatever else which help you make clean, well structured code - that is the basic function of any framework - but there are similar frameworks to each of those in PHP.

If you write code in any language, from scratch, with no experience it's going to get messy. Having a framework to hold your hand is a good way to make it better. That is nothing to do with language at all.

Gravatar
Watts Martin

2011-12-22

I'm aware my post didn't go into any particular detail about what I didn't like about PHP. I could have found some nice things to say about it, or gone into excruciating detail about things I didn't even mention and perhaps should have. In one view, these omissions seem pretty outrageous--it leaves you with an article that's less than a thousand words and just says, in effect, "I've been a PHP developer for years and I'm finding the language increasingly frustrating and eventually I think it's going to collapse, so there." So, sure, if you're a PHP developer who doesn't agree with me, you're going to say, "Gosh, this is a terrible argument."

But the thing is, if I'd tried to go into excruciating detail about, say, why I think PHP's fundamental model of How The Web Works reflects an era of static web pages and is a liability in an era of MVC frameworks, several things would happen. One, the article would be thousands of words longer. Two, I'd have to try to anticipate specific objections ("sure, MVC frameworks have to load all their configuration information and initialize everything on each and every hit of their front controller, but in practice much of that is being cached and the speed penalty is negligible") and try to respond ("that doesn't make PHP's model better, it just means we're very clever at working our way around its flaws"), and I'd probably fail to anticipate everything anyway (as I no doubt have in this somewhat off-the-cuff paragraph).

And three, I'd probably bore the hell out of my readers. :) My blog touches on development issues, but it's not really "about" them. Things that your readers--not to mention the readers of the PHP Advent site!--would groove on are things that would likely make my audience glaze over. And, generally, I try to keep posts at a thousand words or less. Unfortunately, in cases like this, people who know as much or more about the subject as I do are likely to think I'm being pretty shallow.

I'm not unhappy that PHP is progressing forwards--I'm unhappy that for a long time PHP hasn't been progressing forwards. If 5.4 fixes things I consider warts (and it apparently does), that makes me happy. If forthcoming versions of PHP are going to remove deprecated functions and start gently pushing people toward writing better code--which I would argue really is a function of a language's design to some degree--that makes me happy. Understand that while I may be ranty (and you may disagree with said rant), I'm not hoping for PHP to become irrelevant and pointless in a decade. I'd rather be proved wrong than right!

Gravatar
David Register

2011-12-22

PHP gets a bad rep due to lazy development. This comes back to the developer, not the language. To say people that drive a Honda are shitty drivers, doesn't mean that Honda makes a shitty car (just an example, dont have anything against Honda drivers). Behind the curtain PHP does have some issues, but what language doesn't. Once again, I feel that this comes down to the developer. There isn't just 1 way of doing things. If the excuse for your application is "Well its a known issue in PHP", then find another way of doing it and stop being a lazy developer. Its easy to write bad code in any language, PHP is just peoples first programming language. The more popular something is, the more its scrutinized.

Gravatar
Bormacalm

2011-12-22

for you to darkish plus the always-reliable dark-colored <a >uggs for sale</a> which can not only offer enough room for placing ugg cardy boots but can also save room for your house Uggs come in a variety of styles for the whole family: <a >uggs in canada</a> Buy your try it for yourself a couple therefore you will never bum out over the idea all available at more than fair prices <a >uggs on sale</a>The last but not least mateiral used on UGG Australia should be the knitting wools Consider the sewing about the footwear <a >cheap uggs canada</a> grade-A sheepskin is actually extremely thick as well as gentle These are nearly all most likely chosen identified pertaining to establishing comfortable sheepskin ugg shoes or boots for females <a >ugg boots for sale</a>Looking for Selling UGG Boot styles? however advanced design <a >ugg boots sale</a> used using brighter sweatshirts as well as T-shirts along with woolen vests What¡¯s much more <a >uggs boots on sale</a> You may understand the actual divergence It is extremely encouraging to be able to blend any very hot hold between in different fashion-conscious masses <a >ugg boots sale</a> Truth be told there might be not a thing more advanced than a great fluffy Pick up your current match previous for it will be as effectively past thanks pertaining to The holiday season <a >uggs canada</a> Involving people -- I aren't keen on searching normally! Inside the cool time of year <a >discount uggs canada</a> eye-catchy girls have to have some sneakers for every single clothing <a >uggs for sale</a> Note: the boots may shrink a little after washing On the other hand <a >uggs canada</a> it truly is mixed up having knitting and then brings out gentle wool knitting appears to be UGG shoe <a >ugg boots outlet sale</a>UGG shoes are created from a superior quantity merino lambs in addition to hand-sewn The actual Ugg trunk isn't a hard putting on trunk just like a leather-based trunk although <a >uggs in canada</a> dresses The actual Ugg is generally a higher fitted trunk <a >uggs in canada</a> drive apparent associated with putting in it through moist as well as dull climate

Gravatar
Jônatan Fróes

2011-12-27

We will always find a PHP hater and a lover in every corner..

Gravatar
Sid

2012-01-03

I like how the comments switched from PHP to ugg boots and cheap pills.

Gravatar
Paolo Umali

2012-01-03

I learned Fortran as my first programming language because it was required in school. Then when I learned HTML and the web and that I needed a database instead of flat files using lines for records, I ended up knowing PHP.

I find PHP as the easiest to work with for web apps since most hosts supports PHP. Also, as a small time developer(not like Facebook serving up millions and millions, I have not come to a point that I needed to learn a new language to do web stuff).

PHP works and that's why these tools(languages) exist. PHP is easy to work with(what can you ask for?).

Sadly, some people who end up with companies requiring them to use another language looks highly of themselves because they can tag(piggyback) themselves with the new language they learned.

To all nonsense bashers, know that languages are just tools and that the programmer is what's important. A good background in Math and logic, and you having fun learning and knowing how others do things, is a luxury. I guess solid background in theories and being able to apply them, whatever language you are using, makes you a great programmer instead of a piggybacker.

Gravatar
Ivan Prolugin

2012-01-11

@Paolo Umali: are you trying to say that when I know PHP and learn a new language I should not get a better paying job just because I knew PHP first? Forever be a humble slaving webmonkey?

Gravatar
Dami

2012-01-11

I learned long time ago about the value and potential of PHP by reading an article of Jeff Atwood called "PHP Sucks, But It Doesn't Matter".

http://www.codinghorror.com/blog/2008/05/php-sucks-but-it-doesnt-matter.html

Most technologies that get (defacto)standarized on the mainstreem are questionable. For instance JavaScript and CSS could be just an option, but you will be seeing them for a long time on web.

Gravatar
Qwerty

2012-01-22

"like what?"

You mean the thousands of functions shoved into the (until recently) only namespace(ie global)?

You mean how there are sometimes 5-10 methods that do roughly the same thing?

Why is it that PHP defenders know so little about programming concepts? Is there such a thing as an educated PHP fan?

I have yet to meet one.

Gravatar

2012-01-23

Qwerty: Ok what is the base of your problem here.

1.) PHP only recently got namespaces. Well good, PHP recently got namespaces. +1 2.) There are 5-10 methods that do the same thing? That sounds like an exaggeration but I've never had a problem with having options.

You are another developer who assumes that because I use PHP as my primary tool I don't know anything about how "you real coders" do it? Well maybe that sort of comments make you feel big and clever but I've developed plenty of large, distributed API systems written in Ruby, I know how this shit works buddy.

I use PHP for a simple reason: Market share.

I could write the best invoicing application in the world using Erlang, but who the hell would install it? Instead I write one in PHP and it's getting 5 sales a day. Nice.

Check out the top CMS' right now: Drupal, Joomla, WordPress, ModX, ExpressionEngine. What language are they written in? PHP! I'm not defending their code, some of it is written really badly, but I've written a PHP CMS with very neat code and guess what? It's making me money.

It's not a competition to see who can have the shiniest prettiest language and you don't need to shit on people who use something different. I could use a different language for every single project I do, but if that fucks with my sales then why bother?

Ship, ship, ship. Don't just be a dick a whine about things that don't matter.

Gravatar
Paul

2012-01-25

When I first started out writing HTML my code sucked big time but it still worked (almost) does that mean HTML is crap too? Cause if it is and we have to stop using something cause it lets any numpty with a computer be a coder, then I may as well get my application form into Tesco's.

Dont hate the game hate the player, or something along them lines

Gravatar
Jaap Rood

2012-02-19

Reading through all comments I must say I fully agree with Phil. It's where so many technical people driven fail: being obsessed with building the perfect system. At the end of the day, the thing that matters is how your users experience your software, and as long as it does what it does, nobody gives a fuck. Sure, well written apps will scale better, be more stable and easier to change, but since 5.3 and frameworks like FuelPHP this is perfectly possible. The limit still is your own skills and talent in creating an awesome app: no end user will ever use an app because it's written in any particular language, nobody cares.

PHP is still my main choice because it allows me to build apps for clients on any scale. From the ones who want a simple thing that they run on a small shared host, to the big ones that want apps that run on big server farms.

Posting comments after three months has been disabled.