No, PHP does not suck; YOU suck
Jun 4th, 2008 by Gordon | 40 Comments
I'm getting sick of coming across so many PHP sucks articles being parroted all over the internets, so I wanted to dispel some of the myths and rumors about it here. PHP does not suck. Not more or less than any other language, anyway. The most common argument for why PHP "sucks" is that it's "ugly." Forgetting the fact that this is an extremely subjective judgment call to the point of being almost meaningless, PHP is as ugly or as beautiful as you choose to make it. The thing about PHP is that it's multi-paradigm, so it allows you to develop using pretty much any approach you'd like to. You can choose to write procedural code. You can choose to write object-oriented code. You can even choose to write functional code (while it's true that functions are not first-class objects in PHP, you can still emulate the functional approach by passing in the names of functions as strings and then using call_user_func). My point is that you can choose to write your code in any number of different ways in PHP to get the job done. And here's where the problems start.
Because PHP gives you, the programmer, so much leeway with what you can do and how you can do it, you, the programmer, naturally decide to do things in the worst possible way. You write really sloppy, messy, god-awful spaghetti code. And then you turn around and blame the language for allowing you to do that in the first place. It is not the fault of PHP that you're a terrible programmer. Get over yourself. PHP is one of the more flexible languages that I've seen, far more so than stodgy old Java or "hooray for segfaults!" C. In fact, some of the things you can do with PHP are just plain cool and really innovative. For instance, most of the languages you're familiar with use "unnamed" or "numbered" arguments in function declarations, meaning that the numeric order in which you pass in arguments makes a difference (first parameter, second parameter, etc.). A little while back I saw a really neat implementation of calling functions with named arguments, that I've actually extended a bit on my own using ReflectionClass->getConstructor() so that it also works on object constructors. So while PHP doesn't natively support the named-arguments approach like Python does, it's powerful enough so that you can add support for it with very little overhead. That's just plain cool in my mind.
And one other "argument" I see come up more often than not is the one in which angsty, ranting blogger number twelve says "I don't know anyone who would ever say PHP is their 'language of choice.'" Well it's a good thing you live in such a massively broad world and are clearly the authority on every web application developer ever. I do know people whose "language of choice" is, in fact, PHP. I'll even offer one shining example where I have concrete evidence that I'm not just making people up: ME. My language of choice is PHP. I work as a full-time, salaried web developer, I earned my PHP certification courtesy of Zend, and I absolutely the love the language. Don't get me wrong; I know all about the bad side of PHP--the worst part of my job is having to dig through and clean up some of the messy code done by poor developers from years past. It can really be a nightmare. But this is not by any means a flaw with PHP; it's simply a flaw with the people who used it. Once I get done trudging through the filth that some people call "code" for all the wrong reasons and transform it into something shiny and nice, it really can be quite elegant. So while I have seen the worst, I also have seen plenty of PHP's real potential, so I know first hand that it really is a fantastic language if you choose to make it so. (By the way, the language of choice for at least half the people at my office is also PHP. Just sayin' is all.)
Lastly, there are a few other things worth mentioning. PHP is fast. Really fast. One thing we do at work all the time is profile scripts to see how fast they can run in the millisecond / nanosecond / whateversecond. PHP is flexible. Code with whatever paradigm you feel like. PHP is friendly. The syntax is very straight-forward, there's automatic type casting, and plenty of other bells and whistles that go on behind the scenes to make things work the first time. PHP is quite extensive. Some people complain about the fact that PHP has so many library functions, but I'm grateful for them--you can really do a lot right out of the box. PHP is free and widely available. No elaboration necessary on that one. And PHP is growing and innovating. I was recently looking at the meeting notes for some of the upcoming features in PHP6, and I'm actually really looking forward to some of the stuff we'll be able to do. For instance, they're actually including a named break statement (somewhat akin to a "goto" statement) to be able to handle complex nesting structures, and they're making the "middle" value of the ternary operator optional. So the bottom line for me is this: stop bitching about PHP. PHP does what it is supposed to do, and it is capable of quite a lot. If you are experiencing problems with PHP, I'd bet that if you switched over to some other language, you'd still inevitably run into different flavors of the same problems. And I would win that bet, too--not just because I'm made out of win, but because I'd be right.
No, PHP sucks. I'm not saying I'm an awesome programmer, but I write perfectly clean PHP code. No spaghetti, no mess, clean and well-organized. The language still sucks.
Programming in multiple paradigms (functional, procedural, OO) isn't a killer feature of PHP, that's a standard feature of almost any language. Python and Ruby both give you the same freedom. I mean, it's great that PHP *doesn't* restrict you, but let's not play this up like it's a PHP-specific thing, because it isn't.
And you *like* the fact that PHP doesn't support named arguments on functions? I know it's a trivial example, but look: that's code you had to write. That's code you have to debug and maintain. And there's no guarantee that the reflection API won't break out from under you in a new release. It's nifty that the language lets you kind of build a working implementation, but come on, so does every other language! Ruby, for example, doesn't have named parameters, but allows you to easily take a hash as an argument and merge it with a hash of default values. And the syntax for doing so isn't clunky and disgusting.
The bad side of PHP isn't in the terrible code that's written in it — after all, bad code is written in every language ever. The bad side is the *terrible* standard library. You can't defend things like awkward inconsistent naming conventions. You can't defend things like inconsistent order of arguments. Did I want str_replace or strreplace()? Does in_array() take arguments in the form of needle, haystack or haystack, needle? How about stristr()? Good luck answering those questions without looking them up — I, too, make my living in PHP and I consult the manual each and every time for those.
You can say PHP does what you want, and that's fine. And you can say it powers some really fancy sites, and it does. You can even say it's possible to build awesome things in PHP, and I don't disagree. But you can't say that PHP doesn't suck. It absolutely does. The syntax is clunky and awkward — yes, this is somewhat personal preference, but I can't see how typing arr = array('key1' => 'value1', 'key2' => 'value2',) is easier than Ruby's arr = {:key1 => 'value1', :key2 => 'value2,}. Furthermore the PHP snippet there has an insidious syntax error in it.
Like I always say, I love PHP. PHP's gotten my company through some tough times, we've used it to please clients innumerable times in the past. But it sucks, especially when compared to Ruby or Python.
No, PHP pretty much sucks. This is not to say that it is not useful. For a simple Personal Home Page type bit of templating it can be extremely wonderful. At this scale the bloated library and the language semantics are really helpful. Deployment is also very simple. PHP is a tool and it should not be dismissed for the times when it is the right tool.
That said, as a programming language, PHP leaves a lot to be desired. PHP is more flexible than Java and C/C++, but nowhere near as flexible as lisp, python, perl, smalltalk, or ruby (all of which can generally outperform PHP except for ruby). PHP is just kind of disorganized. It doesn't quite know what it wants to be. The massive standard library is really inconsistent, and to really get idiomatic code with PHP one would basically have to wrap all the functionality in a more uniform layer. PHP's approach to being multiparadigmed is kind of hackneyed. It does all the paradigms but poorly. The whole functions not being first class kind of kills it for being proper functional. The object system is improving, but it still feels like an afterthought (which it was). All the paradigms live in their own separate worlds and while you can use them, they just don't blend. Compare this to ruby where the pieces just fit; you use object orientation to support and enhance functional aspects.
As far as flexibility goes, check out smalltalk sometime. It's like a through the looking glass experience. In smalltalk the control structures are even defined using message passing between objects and clever subclassing.
PHP can be used by good programmers to create good code, but it is hardly a good language because of this. It actively gets in the way of code organization and coding best practices, which is a shame because it makes some things so easy.
I like to think I can write good, clean VB 6 code.
That doesn't make it a good language.
Jon, I will agree that the naming conventions are not ideal, but this seems to me to be more of a problem with semantics than with logistics. Just because you have a hard time memorizing some of the function names doesn't make it a bad language.
And the point of the whole named-arguments thing was not to say that I like that PHP does not include this natively, but rather that I enjoy how easily and elegantly you can extend it to. This mostly is a credit to the phenomenal Reflection API that PHP offers. I must confess that I haven't used either Ruby or Python, but I would be initially doubtful to believe that they have as strong features in terms of reflection as PHP does... (correct me if I'm wrong)
Ben... you think Lisp is flexible? HA! And isn't comparing PHP with Perl kind of moot? I mean, didn't PHP start as a fork of Perl?
>didn't PHP start as a fork of Perl
Um, no.
Gordon: Shit, with Ruby, not only do you have a powerful reflection system kind of built into the language, but you can open any class at any point in the application and modify it. This allows you to, for example, open up the Array class, add a method "find_average" to it, and from then on you'll always have the .find_average method on any array you use.
And yes, not being able to memorize things makes the language bad. With most other languages, it's a cache-hit to remember if a function uses underscore vs. camel-case or what order the arguments come in. With PHP it's a cache-miss, which means I've got to stop what I'm doing and look it up. I don't mind looking things up, but not trivial things that should be automatic. I can take someone saying their okay with PHP's syntax — I'm not, but that doesn't mean you can't be. But when people defend the standard library it shocks me. You're a programmer! Find a language that doesn't make you suffer!
(Also, for the record, with Lisp you can define macros that extend the language itself. Lisp is more flexible than anything else out there.)
PHP it's not a fork of Perl
http://es.php.net/history
[quote]
I must confess that I haven't used either Ruby or Python, but I would be initially doubtful to believe that they have as strong features in terms of reflection as PHP does...
[/quote]
You would be surprised. And are you really saying that lisp is NOT flexible?.
By the way I develop with PHP myself and as a language sucks as a platform is quite ok.
If Python and Ruby are so great, how come we haven't seen usable ways to connect them to our web servers?
A friend of mine is a big Ruby on Rails fan and tried to turn me onto it, but then I discovered that (i) I'd need to run a separate ruby process for every application and (ii) need to be waiting for my pager to ring when it goes down. Personally, I manage a large number of small web sites, and I just don't have time for that.
Python? I was a big Python fan around 1999, back when JPython came out. Then I sent some source code files to another programmer and they came back retabbed. It took a few days to find the invisible changes in the source code and get the code working again — it just takes one incident of that sort to waste more time than developing in Python allegedly saves... Not to mention the violent version skew in Python that broke the official Bittorrent client for years — I used to dread installing Java applications, but now hearing that an app is written in Python warns me that installation will be a knock-down drag-out.
Let's see Ruby and Python developers get the basics working before they trash talk PHP. I've got PHP running on hundreds of sites, and you know what... the runtime never screws up, never... and the time I save on system administration I can spend coding, playing disc golf and doing other fun things!
There is no such thing as a language without flaws. PHP has flaws. Python has flaws. Ruby has flaws. And any new web language that comes out in the next few years will also have flaws. People like to trash talk them on the internet when they run into problems. I'm somewhat inclined to trash talk .NET and C#, mostly because my very limited exposure to them thusfar has been quite frustrating. However, I know that if I sat down and took the time to learn them, gave them a fair chance, I'm sure I would adapt and learn to love them (as languages--not necessarily as platforms).
That's actually kind of what happened to me with JavaScript; initially I hated it because of all the browser inconsistencies and glitches. Now that I've learned all the quirks and know how to work with them / around them, I've found that it's actually a pretty clever language that facilitates fast development and that I enjoy.
Trash talking languages is usually pretty futile since, as I said, there are always going to be flaws with any language you code in. It usually digresses into points of semantics and personal preferences (like naming conventions, for instance). There are wars that go on over "else if," "elsif," and "elif," but does the choice of that keyword really make a language better or worse? No. No it doesn't.
PHP is extremely popular, extremely well supported and documented, and widely available. All predictors would say that it's here to stay for quite awhile. And I'm grateful for that, because it's a language I enjoy.
It's a scripting language that isn't dynamic enough for my tastes... It's usable, but I want something more powerful frequently.
It's in a good space though. It's really the only enterprise-ready scripting language out there right now.
Paul: "The basics" is integrating with an Apache web server?
The PHP runtime library is obviously quite stable, as are the runtime libraries of every other viable language out there (be they Python, Ruby, LISP, whatever).
Deploying Ruby on Rails-applications is not easy. This is because of Rails the framework, not because of Ruby the language. But it really doesn't matter, because Rails is made for complex applications, which pretty much always require some care when deploying. And it does have some benefits to not have Apache (or whatever) run the application directly.
You probably consider easy deployment "the basics" because you have only ever deployed small/low-traffic applications that can be supported by a single server.
Back on topic: PHP (the language) sucks. A bit. The syntax is odd and unnecessarily verbose in many cases, lends from a bunch of already-awkward languages (Perl and Java), and makes the programmer write way too much glue code. PHP (the library) sucks. A lot! This has already been pointed out, so there's no need to reiterate.
PHP (the interpreter) is an excellent piece of work, and is both extremely performant and very flexible (can be easily integrated in already running systems). This should be the main reason anyone would ever even consider PHP for serious applications.
Ruby on Rails is very limited in its mindset, but luckily it's not the only web application framework out there written in Ruby.
- Simon
I think PHP in the absence of a good framework is most certainly not a preferable solution. However, alot of the things that these people are complaining about are pretty much nullified when using a good framework. Code Igniter, for instance cleans up alot of the muck. You still have the problem with inconsistent function names and parameter order, and that is something I think the PHP folks need to focus on "cleaning up."
I wouldn't say it sucks, and I do certainly prefer PHPs simplicity over Java hands down. I'm still learning Django/Python and I can say I'm not crazy about python's syntax, but its performance is divine.
As far as Ruby goes, and I'm talking Rails here since I'm mentioning frameworks, I still prefer Code Igniter, the only real thing I like about Rails is Active Record. People try to tell me that the Rails code is more readable, and in some cases, it is. But when you get that one developer so hung up on purity, his code becomes completely unreadable.
I'm off topic here, sorry....
Anyway...PHP depending on its implementation has the capability to suck and suck big time, but it also has the potential to be extremely slim, trim, and elegant.
> it's a scripting language that isn't dynamic enough for my tastes
@Ivan, they said the same about Javascript, you moron. Reality check to all Ruby fanboys, there are no Ruby jobs out there lol.
Java is the next C.
PHP is the nexxt Java.
Ruby is the next Delphi.
Please keep things respectful. There's no need to call him a moron just for having preferences and opinions.
PHP is great! It's the best language, hands down, for those of use who develop and maintain web sites (both simple and complex) and web applications. Easy to set up, easy to develop with, easy to deploy, scale and (assuming the code is well written) easy to refactor.
I've tried doing web projects in Django and RoR and the headaches induced by those frameworks were absolutly uneeded. Things I could do in no time in PHP ended up being a pain in the butt in those frameworks. Sorry, PHP is the best language available today for web work. Period. End of discussion.
Java is the next C.
PHP is the nexxt Java.
Ruby is the next Delphi.
I can't believe that someone actually thinks that.
If you want real performance, you NEED C, you can tell everyone that HotSpot and JIT are making Java as fast as C. That may be true, if you are comparing against crapy C code. Real C developers are crazy about code optimization and they write weird cool stuff that blows your mind.
PHP is mostly for webdev, Java is mostly for big time team enterprise dev, that's why it has all those things to prevent other developers to break your beautiful libraries.
There's a little truth in PHP is the next Java, PHP can't replace Java, but apps are moving into the web, and PHP is already in the web, but it isn't the best choice for web apps, the next widely used language is the one which you can write really great web apps, like Google Docs, can PHP do that?
JavaScript is a great candidate to replace Java as the most used language.
I think php is great. You get nice flexibility, in structure and syntax. If I forget one way to do something, I can probably remember one of the other 3 ways it can be done.
Lisp? Thousands of ( ) and nested recursive loops? Dear god please don't make me put up with that kind of logic when all I want to do is make a small change in a program. I would put it as the complete opposite of "flexible". Painful is more like it.
Python? Great libraries, no question. But the syntax is a pain in the rear. Yes, tabs are great for readability, but I don't appreciate people trying to enforce their vision of how code should look, into my functionality.
Perl? Ugh. I just love looking at hundreds of slashes and symbols, trying to decipher everything. It makes maintenance a nightmare. And yes, in THEORY, it can look lovely and be just as readable as php. But for whatever reasons, perl attracts crazy people who like to obfuscate everything they do.
And ruby I'd like to try more. But, ya know what... No servers have it by default. So when somebody asks me to make a little script for their website, or other minor project, I have zero desire to build a server, and become their system admin and webhost.
Im surprised nobody here is comparing php to ASP? Isn't that the natural choice to compare it against? (I hate ASP btw, but I'll take it anyday over lisp, perl, and python)
PHP sucks because it isn't my ideal language, despite the fact that I'm using it for everything.
The alternatives aren't much better. I don't like Python's style, if you do Ruby you're expected to do Rails, Perl's web application framework style tends to get scarily complex, Java sucks ten times worse than PHP, and MS's .NET stuff generally forces vendor lock-in unless you do something silly and use mono.
I'll stick with PHP despite the suckitude, thank you.
My programming language can beat up your programming language.
PHP has one major problem: Data structures are slow. As long as this is not fixed, PHP will remain a "glue language" that combines high-performance modules written in other languages.
What data structures are you using, Lars? Because last I checked arrays are pretty fast...
No, you're a towel!
What does that even mean?
http://vids.myspace.com/index.cfm?fuseaction=vids.individual&VideoID=4151323
i am coding php for a living (mainly using php 5). i am really getting tired of hearing the same arguments why 'php sucks' over and over. the 'main' argument i always hear is about the inconsistencies in function naming and order of parameters. you guys must be joking. i am using zend studio 6.0 for development and it offers auto-completion and 'tooltips' with 'on-the-fly documentation' (yeah whatever the oh so professional simple term for that is, you know what i mean). and i bet every php ide out there right now does that. so what i am meaning to say is: this does not really matter at all. yeah, i would have to look that stuff up too if i used a basic text editor but i'd probably have to look it up in another language as well.
i agree there are still quite a few essential tools missing for 'enterprise development' in php (continuous integration and such) and i'd love to have namespaces already which are coming up in the next php 5 release as far as i know but for now i am getting along with php 5 really well and we are building our own framework inspired by rails and making use of zend framework components and i think in a few weeks from now i won't want to go back to rails any more. and simply having a look at the zend framework, you can tell that php definitely gives you the chance to produce clean and readable code.
anyway. sure, ruby can handle many things a lot more elegant than php. but that doesn't mean that 'php sucks'. and don't give us that crap about function names and such, it doesn't really matter. it doesn't make you slow. yeah, it's a flaw and basically this mustn't happen when designing a language. but in the end it does not slow you down at all. so come up with something else.
and seeing the progress made from php 4 to php 5, they are definitely on the right track.
Ability to call a function does not make a language functional in any way. Sure I can hack basically any language to do anything I wish to do. So in that sense PHP is multiparadigm = OOP + PP.
Steve:
As a long term PHP developer, first thing I found out that RoR has a faster development cycle for more complex systems. But RoR is a framework, Ruby is the language.
Stop bashing Ruby for that matter. Ruby has syntax rules that allow to create extremely well adapted DSL's, PHP can't match it in its wettest dreams.
You know, all your arguments apply to Perl too. Do you like Perl? Perl does not suck. Why don't you use Perl? Could it be that platform matters more than language?
PHP's problem is not that it sucks (it has some awful weaknesses, and some really nice features). Its problem is the following:
Some languages are criticized for giving programmers just enough rope to hang themselves. PHP, on the other hand, builds the programmer a sprawling metropolis of rope factories. It is so forgiving of stupid mistakes that it can kill you with kindness.
My background: I love Perl and Lisp, have programmed fairly extensively in Java and C/C++, and am not particularly impressed by Ruby/Rails. And I've programmed steadily in PHP, using almost every feature of the language, since 2000.
Shawn, yes I know that all these arguments also apply to some other languages.
I have used Perl, and believe it or not I actually am a fan of Perl. I don't know that I would use it in a commercial environment too heavily for exactly the reason you mentioned--the platform--but it has its uses and it does what it's meant to do very well.
is_set($you) || empty($you) || is_null($you) ???
PHP _does_ suck... get over it...
[...] Facebook use PHP? Why Yahoo? I'd like to link this article because it reflects my thoughts No, PHP does not suck; YOU suck [...]
giku,
isset() and empty() have very specific purposes that I actually recently wrote about, but I will admit that is_null() is a completely useless function. The reason it exists, however, is to maintain consistency with the other is_type() functions.
I like PHP, yeah it has pitfalls but nothing's perfect. I'm getting sick of all this PHP sucks crap, but then I just go to work, write good code, come home and ignore it. I advise you to do the same as the people who hate it will never change and why should they?
Time will tell. If PHP doesn't fix some of its major problems, it will continuously lose great programmers to others like Ruby/Python/JSP/.NET (although I'd not like to see MS to get any stronger, .NET is powerful...). Posts that side-kick PHP can help the PHP team improve the language, optimistically speaking
However, I truly agree to what Gordon said about how "you choose to make it". Yes, that's pretty much what I think about PHP programmers around me.
ps: Maybe I don't have as much authority to talk about PHP since web programming is just my hobby. But really, I've tried all famous/fancy ones and picked PHP at the end, so it is the language of my choice
@Anon (comment #31): http://img367.imageshack.us/img367/1842/hairisabirdym6.jpg
[...] and why. Don't get me wrong, I still love the language (as can be noted by how I've written before in defense of it against some of the typical "PHP sucks" arguments). But I will freely admit that some of the [...]
A PHP-er here (found this page when looking into named arguments)
"This mostly is a credit to the phenomenal Reflection API that PHP offers. I must confess that I haven't used either Ruby or Python, but I would be initially doubtful to believe that they have as strong features in terms of reflection as PHP does... (correct me if I'm wrong)"
Just have to point out here that Ruby's reflection is pretty much its main "killer feature". Even something as simple as bar = foo.class.new() is enough to tell you that Ruby has some serious reflection built right into the language: asking for an instance's class doesn't give you the name of the class, it gives you the class itself, which you can use in a useful manner. PHP 6 is going to bring a lot of neat things, but I still don't see anything like that on the horizon.
PHP6 is going to clean things up a lot, and I really hope that it gets stable enough that I can actually use it in a production environment. Same experience with Ruby on Rails hype being more than it delivers, and I wouldn't want to use rails after the experiences I had with it.
But -- can't knock Ruby's reflection. Try it out. Don't use it in production, just try using ruby. Its simplicty makes it great for prototyping and working out an object model.
What the hell are you people talking about? The PHP Interpreter is a MESS.
That's exactly it! PHP is complete MESS and as we all know, MESS is likely to suck when kept on one place or extended with more of new mess
It not only needs to be completely rewritten, it mainly requires to be thinked about. It is getting even more hybrid and mixed, so imagine you take all mainstream languages and put them to one. Everybody does everything his way and that is why I agree it's bloody sucking MESS.