27 ms·
PHP: A fractal of bad design
- Roccos 15y agoEnough with all these Bullsh!t..., I have already seen too many articles against PHP, If you want developers to switch to other languages, Write an Article on that If you don't like PHP, Just don't fuc_ing use it.. Nobody is forcing you to use it.. Let developers make their own decisions on Which language they want to use. As long as WWW exists developers will use PHP, Get over that.
- aGHz 15y agoWhat exactly is wrong with giving people ample information to base their decisions on? As long as PHP will have all these warts, people will condemn it, Get over that.
- tedivm 15y agoThis is just another example of someone beating a dead horse (which has already been beaten) for page views. Next week we'll have another "bash php" post, and the week after that another. I wish people spent as much time creating new things as they did bitching. As well written as this article is, it contains absolutely nothing that hasn't been said ten thousand times already- in fact, most of this seems to be regurgitated from those other articles rather than being actual original thought. Some of the issues brought up have been depreciated and removed a long time ago- too bad the author didn't limit his google search to the last year when looking for other people's examples to post.
- mellifluousmind 15y agoFor someone coming from other language background, including C#, JavaScript, Ruby, I find PHP absolutely unconventional, odd, unexpected, and inconsistent. This is not a language, where you expect intuitively on what method to call unless you do a StackOverFlow search on existing problems, raised by others like me. Yet, I currently develop a web app on PHP. Certainly, I can't wait to move over to Ruby or other languages in my next project. The author is stating the obvious. But he/she has every right to do so, because PHP is simply not user friendly enough to programmer. If PHP truly targets non-programmer, they totally succeed in their goal.
- tedivm 15y agoI'm not defending PHP, and I'm not claiming the author "has no right" to make their post. What I am saying is that this post has no value, as it's simply a summary of the same posts we see here week after week. This isn't just stating the obvious, this is literally rehashing the posts (he even cites the sources, which I do commend him on) that have already been made. The point is the PHP circle jerk is getting old. I don't see the value in repeating the same discussions every day, and most of these posts just reek of exploitation- these authors know php bashing will get upvoted, so they write an article, submit it here, and wait for the traffic to pour into their otherwise unknown blog. I just think we'd all be better off if they actually wrote something useful.
- daeken 15y agoTo be fair, while the author is a friend of mine, he's not the one who submitted it, nor did I consult him before doing so. So if anyone can be claimed to be exploiting this for upvotes, it's myself, not him.
- stcredzero 15y agoWhat I am saying is that this post has no value, as it's simply a summary of the same posts we see here week after week. Actually, I would state that, "a summary of the same posts we see here week after week," does indeed have value. Now you can bludgeon the next guy who posts a PHP rant with a link to this one.
- jonmb 15y agoYeah, I'm tired of PHP bashing too -- BUT! -- this is probably the best written article on what's wrong with PHP that I've ever seen. So... kudos to the author for a good argument.
- eevee 15y agoMake your mind up—should I have spent less time on this or more? :) Like I said, I wrote it to get this /out/ of my system; I am now impervious to PHP arguments. Either this will convince someone or it will not. Done.
- gridspy 15y agoThe analogy alone was AWESOME :) Well done. Nice to get it out.
- tedivm 15y agoI think you should have spent less time on this and more time on something else. I thought that was pretty clear.
- nowarninglabel 15y agoYou probably also shit after a bad meal to get it out of your system, but although you may have convinced someone to not eat the chicken, the rest of the office has to deal with the terrible stench you left behind, when you could have just gone home and taken care of things in private.
- 0x09 15y agoEven if it's a dried up subject, the blog is comprehensive and concise enough to almost be reference material. Everyone knows PHP sucks but this is a damn good illustration of why. What I'm saying is disregard that guy.
- cageface 15y agoUntil people stop using PHP I welcome detailed critiques of the language. There are still enough PHP apologists out there that we can use all the ammunition we can get.
- philjohn 15y agoWhy do you care so much about what other people use to get a job done? Care about what you use.
- TazeTSchnitzel 15y agoBecause it's not good for the web if more newbies are using such a woefully insecure language.
- tmh88j 15y agoWhy is it not good for the web? Unless an insecure website is leaking personal information, I don't see how that affects you. Besides, how many websites designed by newbies reach hundreds of thousands of daily visitors (or even tens of thousands for that matter)? If said website is so terribly designed, no one would visit it because it would load slowly and be ridden with bugs; no fun.
- optymizer 15y agoHA! The LANGUAGE insecure? Yet another one who blaims the tool. Good luck with your career.
- TazeTSchnitzel 15y agoIt doesn't help if the tool and its documentation encourages bad practices. I don't blame the tool really, I just don't think it helps.
- cageface 15y ago1. It reflects poorly on my profession as a whole if practitioners are too lazy to fix or abandon obviously broken methodologies. 2. It's symptomatic of a general "good enough" mentality that makes software development much more difficult than it needs to be. 3. It breeds bad habits in novice developers that are likely to be my colleagues one day. 4. It steals mindshare and time that might much better be spent improving better alternatives. 5. It provides LAMP detractors with ammunition to shoot at the entire open source web stack. 6. I may one day have a half-assed PHP mess dumped in my lap to clean up.
- sethg 15y agoPeople have been writing murder mysteries for the past hundred years, and some people are still writing murder mysteries, and some people write them in the hope of selling millions of copies. There’s nothing wrong, in itself, with writing about a topic that has been written about before.
- jamroom 15y agoA nice long list of things all concisely put into one blog - I'm sure this took some time to write. Can we move on though? Seriously - no one's forcing you to use PHP, so in your own worlds "It has paltry few redeeming qualities and I would prefer to forget it exists at all." do just that - forget it exists and wake up tomorrow a bit less grumpy. Trust me, you'll feel better!
- greyfade 15y agoMy boss is. Forcing me, that is. I don't really have a choice. I can't afford to move (no, seriously, I can't), and there is no other work that I'm able to do. I dislike PHP. I wish my boss would let me explore alternatives. :(
- jonmb 15y agoYou may be able to do some fancy (i.e. useful and profitable) stuff in another language and show it to your boss. Maybe do this in your spare time while learning another language for fun. It may impress them!
- degenerate 15y agoOh! Do one on motherboard design next! Or the highway system of the eastern US. Or, as others already said, just realize it's warped beyond repair and hindsight is 20/20 for all involved. Very very very comprehensive post, but... yeah.
- whateverer 15y agoWell, you can't really much rip the US highway system off the face of the Earth, and I'm guessing that it's rather inconvenient to route around it, but you surely can not use PHP, and inform those poor misguided souls who believe that it's a standard, or the web's assembler (seriously, I've heard both of those personally!) or that it's, you know, good.
- stcredzero 15y agoLittle new functionality is implemented as new syntax; most of it is done with functions or things that look like functions. That's a problem? I think it's a problem if new functionality can't be implemented as part of a library. I think it's a problem if the best way of implementing new functionality is always to have new syntax.
- eevee 15y agoThere's surely some middle ground, here. PHP defines constants with a function, creates functions with a function, creates data structures with a thing that isn't actually a function but is inexplicably designed to sorta resemble a function. Only now are these basic value definitions getting dedicated syntax.
- stcredzero 15y agoIf dedicated syntax looks that much better than functions, then there is something lacking in the syntax.
- maratd 15y ago> PHP ... bad design PHP wasn't "designed" ... it evolved. Pieces were added, here and there, re-factored, deprecated, etc. etc. PHP is a natural language. It wasn't fabricated at some university, nor in the lab of some billion dollar company. It evolved. That is its strength. It is the most adaptable language around. It can be used for anything and it has been used for everything. And that is why it is the most popular programming language. Not popular with stuck-up pretentious twits who have nothing better to do than to offer their opinion to the world. No, it is popular with people who build things and get things done. That's what it's for. To build. If the clown who wrote that article had spent as much time programming, as he did writing that drivel, we might have something useful to praise him for. Even if it was written in PHP.
- quanticle 15y agoPHP is a natural language. It wasn't fabricated at some university, nor in the lab of some billion dollar company. It evolved. That is its strength. It is the most adaptable language around. It can be used for anything and it has been used for everything. Programming languages are not human languages. Programming languages are engineering tools. Would you cross a dangerous river on a shaky, lashed together bridge that had "evolved over time from a single plank"? Or would you rather cross via well designed, properly tested bridge, even if it was made from the same materials as the evolved design?
- icegreentea 15y agoWell, if you take the engineering analogy in a somewhat different direction, you end up with all the structures we ever created before we mastered statics and material sciences. Those bridges the Romans built were evolved patterns based on trial and error of previous designs, where the last design was the testing. Anyhow, just something to ponder about.
- kstenerud 15y agoThose bridges weren't continually "enhanced" by slapping on more stone and wood (at least not the ones that remained standing for long). Each bridge was a fresh design, based on the best practices of the day. Kind of like new programming languages.
- sedev 15y agoSince my day job is PHP-centric and I was already aware that PHP is awful, this is theoretically helpful to me, but oh lord, it makes my liver hurt. If I could get away with it, I'd never again trust my credit card number to a system based on PHP, but I suspect that that's about as easy as never trusting your credit card to an ATM/point-of-sale machine based on Windows.
- astrodust 15y agoThat PHP logo trick is going to make it easy to spot companies with a wobbly PHP stack. http://www.0php.com/php_easter_egg.php http://www.0php.com/php_easter_egg.php
- tytso 15y agoTry it on Facebook; I guess that means HipHop must not be 100% real PHP. :-)
- haldean 15y agoI can't believe that this is a real thing. The fact that a (purportedly) serious language runtime designed for web applications would have this in it seems like a staggering breach of professionalism.
- astrodust 15y agoIn my opinion using PHP is a staggering breach of professionalism. Would you visit a dentist that used tools as bad as PHP? "Hey, it's not about the tools," they'd scream while you're running away.
- Spoom 15y agoPer the docs[1], this can be turned off in the ini by setting expose_php to Off. So if you tell PHP to hide its presence, it will do so. 1. http://www.php.net/manual/en/ini.core.php#ini.expose-php http://www.php.net/manual/en/ini.core.php#ini.expose-php
- kmavm 15y ago"(And strictly speaking, Facebook isn’t written in PHP; it’s written in a C++ macro language with a striking resemblance.)" I'm a Facebook engineer who works on the HipHop compiler and HipHop virtual machine. It's in PHP, absolutely full stop. It's amazing how much the fact that g++ is involved somewhere in the toolchain confuses people in this matter. C++ is just an intermediate representation; the source language really is warts-and-all PHP.
- jacques_chester 15y agoHe's using poetic license, if that's not obvious.
- kmavm 15y ago"Prosaic license"? If the essay was written in iambic pentameter, it certainly escaped me. Anyway, "C++ macro language with striking similarities" has a pretty precise technical meaning, which sane, literate people might actually mistake.
- ComputerGuru 15y ago"poetic license" isn't the same as "poetic." From the free dictionary: poetic license n. The liberty taken by an artist or a writer in deviating from conventional form or fact to achieve a desired effect.
- deleted 15y ago[deleted]
- eevee 15y agoInteresting. Redacted, with apologies.
- jacques_chester 15y agoOh. I guess you weren't using poetic license.
- ceol 15y agoI enjoy Eevee's posts. I was first introduced to him through a handful of Pokémon sites where users would reverse-engineer the Pokémon games and protocols. He writes good code and knows his stuff. He even offered some assistance when I was writing a .pkm file manipulation package. I completely agree with most everything in this post, too. It can all be summarized in this sentence later down the page: > PHP is a minefield. You can measure a language's design by how often you shake your head at something. I've run in to pretty much every problem he outlines in the Operators section alone. Too often, a problem I'm having is due to a quirk in the language itself and not in my logic. Too often, I find myself needing to check the docs to see which order I need to supply arguments to core functions. It's hard to imagine the pain of working in PHP without working in it. All those little things you take for granted in Python, Lisp, Ruby, etc. are gone. The only consistent thing about PHP is its inconsistence. If you don't mind, I'd like to save this for future reference when someone tells me, "PHP isn't that bad." Yes, as others have said, it was beating a dead horse, but we shouldn't forget just how bad a language can be and still become wildly popular.
- regularfry 15y agoIt often surprises people that WTFs per minute is a useful quality metric.
- ComputerGuru 15y agoMy goal is to move away from PHP completely by 2013 for my websites. I've recently been toying around with various methods of tying C++ to a web frontend, with varying degrees of success. My current favorite method is to use mongoose to create a very simple HTTP interface for any C(++) project (mongoose is great!) and then use AJAX and JSON for any and all communication to and fro client and server. However, this leaves people that have JS disabled out of the loop. My problems with PHP aren't so much the language as much as it is the environment. It's such a mess with so many dependencies that keep breaking any time you want to do a security update. I'm running PHP-FPM w/ nginx on Ubuntu LTS (Lucid), with the suhosin patch, xcache, memcached, and libcurl (I try to keep the external dependencies down to a minimum. PHP's 3rd party libs are so poorly developed and leak memory like crazy. They're also strictly non-TS builds, and will segfault like there's no tomorrow if used in a TS environment.). Trying to keep up with all the security patches means rebuilding a zillion different packages and applying a few dozen patches each time. It's not a piece of cake. As soon as I've found a nice, convenient, and lightweight C++ web interface (wt is nice, but it's very intrusive and all your code becomes wt-specific), I'm planning a series of tutorials and open-sourced projects that can help anyone else interested in dumping PHP. Honestly, it's not so much moving towards C++ as it is away from dynamically typed languages. I've had it with subtle bugs that appear only during run time and only when a certain codepath is taken with languages that let you implicitly define variables. I've come to the conclusion that implicitly defined variables and structures are of the devil himself, and no developer should ever end up working in a language where the compiler doesn't alert you at compile time that your codepath uses previously undefined values. ugh.
- cageface 15y agoI agree that statically typed languages have a lot of advantages but I can't see much reason to use C++ for anything if you have reasonable alternatives. Why not Scala or Haskell or even just plain old Java?
- deleted 15y ago[deleted]
- jacques_chester 15y ago
- mattvot 15y agoI got into the web space through WordPress and naturally progressed into learning PHP. There are times that I wish I could work with another language just as well as I can in PHP. I've attempted to learn Ruby. I know C++/C#/Java/Objective C. Yet I still come back to PHP. I can't explain it. I like PHP. I understand PHP. There are nice people willing to help me with PHP. PHP does what I ask. It's not the greatest. It's no MIT Graduate. But I like working with it. PHP works hard and fast, plus it's a little fun. I feel there is more important stuff for me to do with my life than worry about the structure of a common language. I don't know, if anyone can help me understand my attraction it would be most appreciated.
- deleted 15y ago[deleted]
- mattvot 15y agoI'm sorry to say I'm deadly serious O_O
- shousper 15y agoIn that case.. - I feel there is more important stuff for me to do with my life than worry about the structure of a common language. I actually think you answered your own question :) A love of simplicity is as meaningful as a love of good structure, consistency or design. I envy your ability to -not- want for something better.
- daeken 15y ago> EDIT: note to self "-x points" = x many people with limited sense of humor or very old and don't get it.. /sigh.. HN is not a site where you just drop a meme image and walk away. Humor on the site is appreciated if it's contextually relevant and clever. This isn't Reddit.
- shousper 15y agoIt was a question, and mattvot answered it.
- Deinumite 15y agoI completely agree with all of the author's points, but my day job is still PHP and I actually don't hate it so much now. That being said, it's nice to be able to sit on the most version of PHP and use awesome frameworks like FuelPHP and Laravel. I would not really consider doing anything besides nice CRUD app's in PHP though.
- astrodust 15y agoThey say eventually you learn to love your captor. Frameworks can help a lot, but what PHP really needs is an equivalent to CoffeeScript that fixes all of these glaring issues with PHP. Although there's issues with the PHP language implementation, the biggest problems are the enormous number of functions with quirky argument ordering that need to be understood by a developer before they're operating at full efficiency.
- HerroRygar 15y agoThere's a CoffeScript-ification of PHP called Snow. You can see it here: http://code.google.com/p/php-snow/ http://code.google.com/p/php-snow/ Frameworks definitely help a lot. I've done a little work with FuelPHP, and I found that to be pretty pleasant.
- astrodust 15y agoIt's all fun and games until you want to find a string in an array. The entirety of the PHP API should be bundled up in a burlap bag, beaten savagely with a baseball bat, then thrown in a shallow grave to be set on fire before being buried. The "Goodfellas" treatment is way too kind in this case.
- Osmose 15y agoI'm going to be unfair and quote just two words from the article: > empowered amateur PHP is a gateway drug to web development. And that's awesome. With almost every other popular web development language I've heard of[1], there's this grey area between "my app works on my local machine" and "my app works on the server" that is really hard to grok as a beginner. There's a reason entire businesses are built on the idea of making this easy. With PHP? You get an apache box with PHP, you put the files up, and you're done. For a professional web developer? PHP is probably nuts. I've purposefully left out things like PHP frameworks, setting up a database, or doing any sort've advanced web development. And yes, it is possible to create a large, successful, stable web app with PHP. It seems kind've hard given the legitimate criticism in the article. But, honestly? Once you've started doing web development, you should be able to improve your own skills without the community pushing you. It's the people who are just starting out who need all the help they can get. [1] Which isn't at all exhaustive. I'd love to hear about alternatives that are beginner-friendly.
- djmdjm 15y agoIt's not awesome if the applications so developed by amateurs grows to store PII, financial information or do anything that has any security consequences whatsoever since it is likely to be riddled with "game over" security vulnerabilities. Unsurprisingly, most PHP applications end up in this state. Cf. http://web.nvd.nist.gov/view/vuln/search-results?query=phpbb&search_type=all&cves=on http://web.nvd.nist.gov/view/vuln/search-results?query=phpbb... - and phpbb is one of the popular ones with an active community...
- patio11 15y agoMost applications developed by professionals in Big Freaking Enterprise Languages working in regulated industries will also have game over security vulnerabilities. Most applications developed by the cool kids in Ruby/Python working for startups will have game over security vulnerabilities. The current state of information security: basically, we're screwed.
- daeken 15y ago
- robomartin 15y agoI can't really fault anything that was said in the article. What left me wanting was the ending. I was expecting the equivalent of the main character happily walking into the sunset. In other words, something akin to: "And now that we have established why PHP sucks let me tell you what I use and why. I use <language/languages>. Here are all the reasons for making these choices:"... To me at least, an equally thorough treatment of what he might consider the "right" or "good" language would have made the time invested in reading the bitch-about-PHP feel more valuable. You'd walk away with at least one well-studied view for a potential direction away from PHP. As the article is currently written you are told all the reasons why what you are using is shit but not given any hint as to what you might consider looking into.
- eevee 15y agoHa, I actually avoided doing this so as to not sound like a shill for better-thing-X :) I namedropped Python a couple times, and I do enjoy it for webdev. I've been considering writing something about getting into Python webdev from a purely PHP background; might do that sooner rather than later.
- jasonlotito 15y agoAs someone who goes to PHP when he needs to program for the web, and has been doing so for some 13 years now, seeing the horse beaten again didn't move me. I can't say I spent much time on your article, mostly because at this stage of my life, focusing on the negative doesn't earn you anything. I say that because, while it's clear you spent a lot of time on this, it's not really useful precisely because you don't provide any direction. Who is this article for? New people? They aren't going to understand half of what you wrote, but more importantly, they don't know where to turn to for the next step. You mention Python. And that's cool! Python is an awesome language. Your target audience (new programmers or new web developers) aren't going to read through that entire thing. The only people who will are PHP developers who want to respond and people already hate a programming language. What would be valuable is if you took a look at why people pick up PHP, and instead of trying to destroy it's existence with a single post, you actually show them how they can use Python to do what PHP does. You've clearly done the research, so you know where PHP's strengths are, and why people still navigate toward it. Anyone can destroy. It takes actual effort to create. Help create. =)
- LeafStorm 15y agoI admit, PHP sucks. But there is one thing it has going for it. It's simple to configure and secure a server that your general userbase can run applications on. I work at ITECS, the Engineering IT department at NC State University. ITECS is responsible for maintaining the server infrastructure for dozens upon dozens of university Web sites, most of which have dynamic content. Not to mention the people server, which anyone affiliated with the College of Engineering can get directory space and a MySQL database on. I was once talking to our Systems people about, why not allow Python applications. They said that every time they have experimented with allowing CGI scripts in any language supported by their Web servers, someone has always found a way to exploit their sandbox. With PHP, the applications can still get exploited, but they have never had a breach that affects the servers themselves. So if you're a startup or a major tech company who can spend time customizing a Web server and trust everyone who has access to it, then you're crazy for using PHP. But if you're a college with 8,000 students, almost 1,000 faculty, and a bunch of support staff in addition, and a good quarter of them need Web sites, PHP's pretty much the only option that will keep you sane. In my opinion, that's something that seriously needs fixing. But it's certainly an explanation for why PHP is still around now.
- eevee 15y agoWhoa. Definitely don't run Python as CGI. Use WSGI, run your app as a devoted low-priv user, proxy to it. Then you have only one entry point; there IS no sandbox, and nothing to exploit.
- shuzchen 15y agoI agree. Why not run the webapp as the user account the code belongs to. With virtualenv and pip, normal users can install modules into their own site-package in their home folder, and any runserver started as them will only have permission to access anything they have access to. The only thing that is possible to exploit is what they've allowed in their code, but that's pretty much the same issue you have with php.
- LeafStorm 15y ago
- yaix 15y agoDon't complain about it, simply don't use it. The language seems to be good enough for some of the largest sites out there to use it as their primary langauge.
- astrodust 15y agoThese complaints are all well founded and researched. They serve as an education on what not to do if you're working on any computer language or applications with an API that are used by others. "Good enough" is not good enough. COBOL was "good enough" for many companies. We can do better, and we should try to.
- sneak 15y ago"preg_replace with the /e (eval) flag will do a string replace of the matches into the replacement string, then eval it." The mind reels.
- astrodust 15y agoYou can blame Larry Wall (Perl) for that one. It's amazingly powerful but also the stuff of nightmares in the wrong hands.
- eevee 15y agoNope. This works as you'd expect in Perl: the replacement is treated as code and executed like an inline function, never eval'd.
- astrodust 15y agoIf you're implying that `/e` is more dangerous in PHP than in Perl, then that is truly terrifying.
- shabble 15y agoYep, that's why s///ee exists :) http://perldoc.perl.org/perlop.html#s/PATTERN/REPLACEMENT/msixpodualgcer http://perldoc.perl.org/perlop.html#s/PATTERN/REPLACEMENT/ms... "e Evaluate the right side as an expression. ee Evaluate the right side as a string then eval the result."
- deleted 15y ago[deleted]
- vivekprakash 15y agoI had a one-to-one talk with Rasmus Lerdorf a few weeks ago. This is one of the few things he said: "I wrote PHP as a hammer to do my stuff. Around 1993, the only way to write web apps was by hacking C and Perl. This was extremely painful, and you would have to do the same thing over and over again. So I started writing a tool which would make my work easier." "I never thought while writing PHP that someday millions of people will be looking over my shoulder into my code. If I would have known that, I would have surely done a few things differently. But nobody knows that. Some appreciate the language, some don't. I don't blame them." "PHP is a hammer. Use it for the right purpose at right place. Learn Python, Ruby, Haskell, Scala, etc. every language and use them where they fit. No language is perfect. There are trade-offs involved in each of them." "When anything is too popular, criticism naturally follows. When people compare a language which is used in, say, 35% of the web apps to a language which is used in, say, 5%, their comparison is highly skewed because then they directly compare the number of things that have gone wrong in one with respect to another. They don't scale them to the same level and then see the faults. I don't blame anyone for that." "You can scale horizontally with PHP as much as you want. There are many companies doing that, and they have been very successful." "I can teach a semi-intelligent monkey to code in PHP in three hours." There were many other cool and brilliant things he pointed out. What I learnt: Accept what it is. If you don't like it for your purpose, use another language which fits in. P.S. In the new release of PHP, there are even driven servers (libevent), Support Vector Machine (SVM), Traits, Instance Method Call, built-in web server for testing, improved error messages, broad performance improvements, and many others. This language is not going to go away soon.
- fruchtose 15y agoAs far as I understand it, the real tragedy is that PHP as used at scale. PHP as Lerdorf intended it was the quick fix, the we-need-to-get-it-done-now fix. And then that fix grew and grew until the things that PHP fixed were eclipsed by the things in PHP that needed to be fixed--but PHP was already too big to be fixed; people were using PHP not just for fixes, but for everything, and to fix everything would break everything... And that's how we got here. Because nobody will understand your intention when your code is on the screen and the intention can only be inferred from someone who is not in the room with you.
- pcwalton 15y agoA nit: "Subclasses cannot override private methods. Subclass overrides of public methods can’t even see, let alone call, the superclass’s private methods. Problematic for, say, test mocks." IMHO you don't want private methods to be visible in subclasses, because this makes the fragile base class problem worse. If I'm a framework developer working on a UI library, I should be free to add private methods to my Button class for the second version of my library without worrying that they'll influence the behavior of a FooButton that some app wrote that's derived from the class in the first version of my library. The problem, of course, is testing. You want to be able to cleanly substitute mock objects for unit tests, without having to make everything depend on an interface or to use protected everywhere. It'd be nice if languages had more unit testing facilities built in. Microsoft Fakes is an interesting approach here.
- eevee 15y agoWell, that's coming from the perspective of someone who doesn't like "private" in the first place; it forces me to rely on whatever use cases the author has imagined and makes extending the class in a novel manner a pain. Except this is PHP, so I can just go change the "private" to "public" anyway. Namespacing within an inheritance tree is a problem, yes, but just hiding as much of your namespace as possible sucks. As does ahem ahem double-underscore prefixing. Surely there's another option here, but until someone figures out what it is, I'm okay risking collisions.
- wvenable 15y ago> it forces me to rely on whatever use cases the author has imagined and makes extending the class in a novel manner a pain It's purpose is to isolate you from implementation details you're not supposed to care about and allow the library/framework developer to update their code without fear of breaking your components. It's also a form of enforced documentation.
- fusiongyro 15y agoI agree. Blaming PHP for copying Java is a little absurd.
- 15y ago
- jmspring 15y agoI'll preface things with, I don't care about the cleanliness/consistency/correctness of languages, I really just care about tools to get a particular job done. PHP isn't sexy, hell, it might be classified as a backwater these days. Fact is, it is a simple language, it works, and a whole lot of useful tools are built on top of it. I've done many bad things with PHP, some I will admit to, some I won't. Hell, I built a bunch of authentication services and prototyped a storage backup system using PHP because it was the most mature language at the time (this was years ago, and mod_php was light years ahead of mod_python, ruby wasn't even in the discussion). It worked, the security issues were known, and we knew how to scale the system. The first post on http://anodejs.org http://anodejs.org a couple of weeks ago was pretty amazing. The title "We work at Microsoft and we use node.js". That statement in itself was amazing (you wouldn't have seen that 5+ years ago), but the use of Javascript in a large company/large team environment is an interesting exercise. My experience is that a team of 4-6 people working in the Javascript/Node server side have to put tools in place to ensure code quality and consistency that was never needed in PHP. Each language has it's strengths and weaknesses. In the case of PHP, it isn't sexy, it is pretty homely, but a lot of people are still getting a lot of stuff built using it.
- TazeTSchnitzel 15y agoYou know, with Microsoft people using node.js, Microsoft is actually really friendly towards JavaScript at the moment. They have made proper JavaScript debugging tools and Visual Studio integration!
- peterwwillis 15y agoPHP was designed by people who neither knew, nor cared what the hell they were doing, but knew they wanted something to do what they wanted to do. In that sense you cannot blame PHP for being a huge wasteland of terrible design just as you cannot blame a blind man for not being a great painter. That being said, thank you for documenting why nobody should ever seriously use this language unless it's absolutely necessary.
- sandwitch 15y agois there a major new startup that has been built with php in the last couple of years ? can you name one ? http://www.reddit.com/r/PHP/comments/rh3u2/any_new_major_startups_built_with_php/ http://www.reddit.com/r/PHP/comments/rh3u2/any_new_major_sta...
- joeuser12 15y agoYes, quite a few, as that thread shows.
- dasil003 15y agoAs pointed out in the comments there, 2 years is not really a big enough window to identify a "major" startup.
- eurohacker 15y agoInstagram is younger than 2 years, isnt it
- ahupp 15y agoIt would be nuts to consider starting a brand new, dependency-free project in PHP today for all these reasons and more. If the reason for doing that is "all I know is php", well, now you have two problems. That said, my primary language is PHP and I've written a whole lot of it over the last few years. I can report back that the choice of language is somewhere around the 37th most important factor in the end result. Whatever its flaws, they just don't have that strong of an impact in reality.
- sourishkrout 15y agoI wish I could give this post 10(gazillion) votes.
- ericd 15y agoMeh, I've written a lot of PHP code. I also work in Ruby and Python. All three have problems, but I like all three. With PHP, you have to develop a coding style that naturally avoids PHP's weird areas. It's not really that hard to avoid the mines, but you do have to be aware of them. In exchange, you get a scalable web server and a language that requires minimal babysitting. Instead of automatically throwing a 500 on a random, unimportant, uncaught exception, PHP makes a best effort, and most of the time the result is fine. 99% of the time, this is better behavior from a user's perspective as long as functioning perfectly isn't mission critical. It may feel offensive to your OCD programmer nature, but from a pragmatic engineer's standpoint, it's oftentimes a better choice, especially when dealing with the dirty data that's so common in webapps. Do not use PHP in a banking setting. Compared to running a rails app, administering and scaling mod_php is pleasantly hassle-free. A single webserver with a modest amount of memory can handle an large number of concurrent PHP processes and requests without needing to resort to reverse proxies or anything more exotic than a simple apache install. That's nice not only for the ease of setup, but also because it means fewer moving parts, and less maintenance. That's a very real plus, and I'd say that the shared-nothing architecture of PHP was great engineering choice. Yes, the language is weirdly architected and oftentimes inconsistent. It can also be extremely productive, and many of its weird choices are extremely pragmatic. The security holes are pretty horrifying, though - the defaults should be much more locked down, and I've always been a bit mystified that they're not.
- stiff 15y agoInstead of automatically throwing a 500 on a random, unimportant, uncaught exception, PHP makes a best effort, and most of the time the result is fine. And how precisely does PHP "know" which exceptions are important and which are not? In my experience of 6 years as a web developer, the faster and the more explicitly something fails the better. If the user gets a 500, that's a pretty clear sign of a problem, I get an email notification about it, including user id, session data etc. Then, in most cases, I can easily see what the problem was, decide what the correct behaviour is and create a fix immediately and even notify the user after releasing it if I wish to do it. If there is no exception there is a case in the code I was not aware of when writing it and it will still not be brought to my attention. In the best case, the user will report some problem with the functionality and I will have to spends hours trying to find the logs for this user and reproduce the problem, which will now be much harder, quite some time could have passed since the error, the database entries for the user could have change meanwhile (including corruption caused by the system continuing to operate despite an error) and so on. In the worst case, the bug will continue to affect users (which might not even know what the intended behaviour was) and I will learn about it a year from now, accidentally. Reproducing bugs is hard enough in web applications due to their distributed nature, some of the applications I worked on had serious business-affecting bugs that went unnoticed for months and failure to clearly signal errors is one of the common cases. It doesn't matter whether you are in banking or just building another social CMS/CRM "kind of thing", if you have bugs you loose users and with them money. See also: http://en.wikipedia.org/wiki/Fail-fast http://en.wikipedia.org/wiki/Fail-fast
- drivebyacct2 15y agoI regularly, (all over this thread), see people swear that PHP is great for beginners. Everything in this article seems to indicate the opposite. You have to trip over PHP's poor design while trying to learn to program. Outside of the wide availability of PHP servers for cheap, what makes PHP so great for beginners? With Ruby, Python, Go, hell, even JSP for the "instant", in-HTML effect, I just don't see PHP as some gloriously "easy" language to use. On top of it, there are hundreds of thousands of PHP tutorials all across the Internet that just have poor, poor, poor suggestions and design patterns that lead to people storing passwords unhashed, or unsalted. Sure, it's not unique to PHP, but it's really, really easy to get wrong in PHP and that's painful for a beginner and it's hard to progress and mature as a PHP developer without an existing code base to learn from. tl;dr: I'm not convinced is as great as many here make it out to be. (To note, the first thing I sold was written in PHP in highschool. Since then I've used JSP/J2EE stack/python/ruby and now am infatuated with Go, so my opinion is not simply based on group-hate for PHP)
- comex 15y agoWith PHP, creating a new "app" is a matter of sticking a .php file in a directory. There is no config file, directory structure, or server to babysit, and nothing to restart after modifications. Instead of using a complicated templating system, you just include HTML inline. This is a horrible design for a large webapp, but even as an experienced programmer, sometimes I just want a quick hacky self-contained script, like the many, many .py files in a subdirectory of my home directory (but on the web, Python does not provide this convenience in commonly used setups). A beginner can similarly benefit from simplicity: even if Rails tutorial code is pretty, there is still a lot going on behind the scenes; sometimes, the smaller conceptual model required to really understand what's going on, the better.
- slurgfest 15y ago"Sticking a php file in a directory" is just a matter of server config, not languages. There is no reason why you can't put a quick Python web app in a single file which exposes just one WSGI application object named 'application' - so if the server complied, you could indeed just stick the .py file in a certain magical directory.
- atacrawl 15y agoSure, PHP is full of inconsistencies and irregularities. You know what else is? English.
- natbat 15y ago... and that's why we don't use English as a programming language.
- TazeTSchnitzel 15y agoYeah, good programming languages are a lot more like Latin than English. They have rigid grammatical structures and consistent vocabulary.
- eblume 15y agoWhat English is good at is expressing a huge variety of ideas. I once heard someone argue on NPR (sorry, no citation) that English is perhaps the /best/ language at expressing absolutely any idea to another person precisely because it has such a huge vocabulary and so many idiomatic phrases. I've sometimes heard of programming as an art, like poetry, but if so I'd prefer to maintain that it is a minimalist art that enjoys pragmatism and flourishes when reduced. Put another way - I don't want to write 'A Tale of Two Cities' in PHP, I want to write a website in PHP. Or more correctly, I don't want to write a website in PHP.
- sjwright 15y ago> I once heard someone argue on NPR (sorry, no citation) that English is perhaps the /best/ language at expressing absolutely any idea to another person precisely because it has such a huge vocabulary and so many idiomatic phrases. I heard that on the radio, and I've been looking for it for years! If anyone knows the show, ideally the specific show or interviewee, I'd be supremely grateful!
- eblume 15y agoI think it was a Science Friday, if it helps.
- gbaygon 15y agoPHP is a tool. If it's the right one for the job, use it with a good framework, especially CodeIgniter.
- alecco 15y agoA client's system has PHP scripts in its crontab. Just imagine the wonders those files have inside.
- conradfr 15y agoI work for a very large ISP. When I get there I found that a lot of tools are done with PHP, and I'm not talking fancy PHP. mysql_, no APC, no framework, almost no objects, no web services etc. The other day I was asked to do a cron task and I was able to do it with Zend Framework very quickly and quite elegantly. It was surely not the perfect tool but since it integrates with the culture of devs and sysadmin there it was certainly good enough and very maintainable.
- alecco 15y ago"If all you have is a hammer, everything looks like a nail."
- eurleif 15y ago>Why on Earth does the parser need to know about empty? empty() doesn't issue a notice if the variable isn't set, like it would if it were an ordinary function. It's basically isset() with extra functionality. That makes it useful for checking form variables: if (!empty($_POST['foo'])) { ... }
- lbj 15y agoSo the pendulum swings. A little more than a year ago 'The ducttape programmer' was all the rage and he was by definition a PHP programmer.
- wvenable 15y agoI can't believe this article is on the top of this site. At least 50% of what's written in there is totally wrong/false. Other information is terribly out of date. And even more information is merely half-truths and lack of understanding of the language. Even pure supposition like "PHP was originally designed explicitly for non-programmers" is incorrect. This article is garbage -- don't be taken by it. I'm not going to argue that PHP is a great language, but this article is a complete disservice to anyone who has bothered to read it.
- eevee 15y agoPlease enlighten me! I'm interested in correctness. The "non-programmers" remark refers to a quote from the PHP 2.0 documentation. I tried to minimize the editorializing.
- wvenable 15y agoNearly every other item is wrong; I didn't bother listed them all because it would just take too long. I'm actually still reading the article since I posted that comment and I'm still finding errors.
- enneff 15y agoYou would do us all (author included) a favor by pointing them out. Why would you take the time to complain about the articles veracity without providing a single correction?
- Shank 15y agoMy major gripe with PHP is the lack of predictability. I end up having times where I say, "I know there's a method to do this" but my fuzzy autocomplete is drawing a blank. I google it, and it's named something completely different than what it should logically be. mysql_escape_string is a good example.
- nikcub 15y agoPHP is just an interpreted C and standard libs all rolled into one. The first version was literally a set of macro's. PHP has baggage that other languages don't because of its immediate and rapid super popularity. If you look behind each one of the features you will find that they aren't 'design decisions' but rather a consequence of circumstance. Most of what is being discussed in this post doesn't really matter because: a) most PHP developers will never touch some of the smaller nuances b) newer versions of PHP are changing things (and people still keep using older version. there was an entire holdout movement with version 4). this entire post could have been pulled from the PHP issue tracker. c) super duper huge websites and web applications are being built with PHP I don't consider myself a PHP developer, but the argument about it being useless in spite of all the evidence is just ridiculous.
- JohnnyFlash 15y agoErm... OK... use something else then. Fortunately there are many options when it comes to web development. You don't like PHP? Avoid it! Do not use it! Use Ruby or something. I used to get cranky about Facebook. Now I don't use at all.. what do I feel about Facebook now? Nothing. No point getting your pants in a twist about something that doesn't need to a part of your life.
- arocks 15y agoOne of the main reasons why I am so scared to use Wordpress is PHP. The article does a good job explaining why security holes in applications built on PHP wouldn't be a surprise. The only alternative is to constantly upgrade to the latest version. Sometimes, that breaks things like plugins. That is too much overhead for a blog.
- corford 15y agoYou should be scared to use Wordpress because it's Wordpress. I don't know a single experienced PHP developer that has a good word to say about Wordpress's code quality.
- skrebbel 15y agoLike many, I've grown up with PHP, and grown to dislike it big time over the years. However, it has its virtues. Now, my rule is: use PHP iff it feels like the entire script could comfortably fit inside one small PHP file. The moment my very first design feels like it's better to, say, separate the view from the controller, use a real language. Sometimes this estimation is wrong, and I end up rolling my yet-another-PHP-microframework over again, but usually this is a pretty decent rule of thumb. I don't want to have to go through setting up a VPS and a rails environment for something that'd take me the same time to coe and deploy in PHP. Really, PHP is excellent for what it was originally designed for: little server-side scripts that do relatively simple things. I know that its authors would currently like it to be used for more than that, but, well, don't. As long as you're not making a massive application, PHP's massively filled global scope, decent batteries-included approach, documentation-with-examples, and its support on virtually every web host (and then some) make it an excellent choice. Therefore, I disagree with the author's notion that it's bad for everything. It's excellent for little scripts, which is was mr Lerdorf originally intended it to be for anyway.
- eevee 15y agoI used to concede that PHP is appropriate for little scripts, but I changed my mind over time, because so few of those scripts stay "little". Where is the line drawn? Do we find we need a new feature one day, decide that's enough to tip the scale, and set out to rewrite the thing—wasting all the time purportedly saved by writing it in PHP in the first place? We're lazy, so probably not. I tried writing a little one-off Python thing in Flask last year and was actually surprised by how little effort it took. I spent more time learning Flask (and Flask is really, really simple) than I did actually deploying the thing to a VPS with spare cycles. It could stand to be slightly more turnkey, but running a tiny app server isn't nearly the nightmare it's made out to be.
- skrebbel 15y agoDidn't we all go through this? 1. Ooo, PHP is awesome, I can make stuff happen on a server! 2. Hm, well, PHP has its problems, let's open source a microframework to fix it! 3. Oh my god, PHP is horrible, let's rant about it on a blog! 4. Who cares that PHP is horrible? It's the application that counts. OP is at step 3, currently.
- human_error 15y agoNo, not all of us. I've never coded anything with PHP. I don't even know how to write hello world with it.
- anthonyb 15y ago5. Oh fuck, I've been hacked!
- eevee 15y ago
- tylermenezes 15y agoMost of these are legitimate points. 95%-99% even. Some of them are certainly preferences, however, and that bothers me. If PHP were designed to satisfy all of the complaints, we'd end up with something fairly similar to python with curly braces. I would really like to see PHP take the time in the next version to fix all of the inconsistencies.
- michaelkscott 15y agoA little background about the author (Eevee) might help, for new readers. Here's some stuff I've picked up from his about page (http://veekun.com/about http://veekun.com/about) He loves Pokemon (really cool depending on how old you are) He's "extremely picky about software" He, "tend to rave about bad products a bit too much. After having been bitten by it too many times, I can't stand sloppy languages or sloppy databases."
- BoldAsAnEagle 15y agoIf PHP really is so shitty, can you please in any other language or framework of your choice finish the following project in 10 minutes, Be able to put a <yoursolution>.<YourLanguageFile> inside any folder where your apache/nginx serves fiels from, then make your file give a much nicer file listing than the default of nginx/apache with possibility to comment on the file (using a __comments/directory and text file for each comment and sequence number as filename). Come back when you have to struggle with various "deployment" options in django/flask and .war files.
- eevee 15y agoI've done this several times with Perl. It wasn't difficult. The template was a blob of TT in a __DATA__ block at the end of the script. Deploying as PSGI would take, like, three lines of nginx configuration and wrapping the bulk of the script in a function.
- mmobile 15y agoTry node.js + express with some turn-key hoster like Nodejistu (which deploys as fast as some ftp transfer of some php files)
- slurgfest 15y agoHaving Apache automagically serve a WSGI app object found in foo.py when you dump it in /opt/magicpath has nothing to do with the language and everything to do with Apache.
- kikito 15y agoHow about doing the same without Apache?
- mechanical_fish 15y agoAll those words, and yet the word template only appears once. And that's to assert that PHP has: …no template system. There’s PHP itself, but nothing that acts as a big interpolator rather than a program. As if that was a bug and not a feature. PHP succeeds because there is one PHP templating syntax and it is called "PHP". PHP started life as a templating language, and that's where its soul lies. Which is important, because if a non-programmer wants to start editing dynamic HTML pages, most likely the first thing they open in their text editor will be a template. And if a customer wants to change the website, but doesn't want to pay a highly-trained programmer (we're very expensive, especially because none of us really wants to be paid to edit templates all day), they'll hire someone who knows how to edit the theme. For every seasoned programmer in the world, there are half a dozen themers who know how to edit HTML and CSS, and maybe how to embed a "foreach" loop that calls a stock WordPress function, or edit an argument list, or swap one Drupal function name for another. And for every themer there's a dozen non-programmers who dream of knowing enough to be themers. This class of user is what every other platform tends to neglect. Ruby and Python programmers tend to design tools that are intuitive to other programmers. We build "frameworks", where one must tinker and monkey-patch and fork to such a degree that only another programmer can download and assemble a working system, let alone customize it. (One word: Gemfiles.) We write programmer-centric documentation filled with jargon terms from Javaschool, like "object". (PHP themers often do not understand OO, and often don't need to. This, all by itself, could be why PHP is so popular.) But one leaves a lot of money on the table when one designs software systems exclusively for users whose programming education entitles them to six-figure salaries. There aren't enough such people on earth; that's why they earn six-figure salaries. Designing the minimum viable product for borderline-non-programmers who want to tinker with dynamic web pages is hard work, though. PHP evolved into that niche, but if you don't start there it's hard to steer there deliberately. For me, trying to remember when object inheritance and version control and function definitions were mysterious is like trying to remember when I didn't understand algebra. (And, believe me, I really didn't understand, once. But I'll be damned if I can remember why not.) It's so hard to keep one's eye on that ball that even the PHP developers lost the plot long ago: PHP has long since bulked up with features borrowed from other languages. But if you ignore its newer features the soul of PHP is still a little templating language that you can edit into the HTML on your server; change a filename extension and reload and you're good to go. And, the thing is: You can write a crazy-complicated core system in PHP, but then expose it as an API at the template layer, and those tinkerers hacking at the HTML on their servers will be able to use it.
- mmobile 15y agoI've been to some conference lately and next to me was a guy sitting excited about the high traffic system he's building—I asked about the language he is using: He (playing with his iPad 3): PHP Me: I thought PHP devs died out for years?? He (angry): PHP is still the most used language for the web and it's fast. Me: Do you guys still mix front-end and back-end code? He (still angry): Of course not. Back home I started googling "PHP" and "PHP frameworks" for the first time since 2003 again. I was surprised: there are many Rails-inspired frameworks like Yii, Zend, Codigniter, etc. And I tried to be objective giving PHP another chance (I haven't an actual use for PHP but I was just bored and wanted to be prepared for better counterattacks next time). My impressions: - There seem to be too many frameworks or call them ecosystems, so I couldn't figure out which is the dominating one (Zend?). And I am not sure if they are really interoperable - Not relevant but awkward: most frameworks websites (except Yii) and in particular the PHP site look like 2003. What disturbed most was the often used claim "no console needed". - On Freelancer.com, Monster or any other job-related site the quantity of postings for PHP devs were massive—any other web-related fraemwork/language else like Ruby, Python, Django was a small fraction oft that. After looking at some "modern" PHP code (which strictly follow the MVC patterns now) I still couldn't get warm with PHP. I assume that most PHP devs are long-time PHP devs and I don't understand how PHP can attract people compared to newer concepts.
- corford 15y agoIMHO the only two PHP frameworks you need to care about are: Symfony2 (think a PHP equivalent to Django or Rails) and Silex (think a PHP equivalent to Sinatra). I've just spent the weekend porting an old site to Silex and Twig (a PHP equivalent to HAML) and its been a breeze. Both frameworks come from the same people and have excellent documentation and support (i.e. they are not run by a couple of geeks somewhere who might suddenly stop developing them once they get bored). See: http://symfony.com/elevator-pitches http://symfony.com/elevator-pitches
- getsat 15y ago> it's fast. People honestly still believe PHP is fast? Wow. Even Ruby (1.9, YARV) is as fast as PHP nowadays, and it's one of the slowest mainstream scripting languages you can use right now... http://shootout.alioth.debian.org/u64q/which-programming-languages-are-fastest.php http://shootout.alioth.debian.org/u64q/which-programming-lan...
- kaolinite 15y agoI agree with every single point here and I work with PHP for a day job. It's a horribly designed language that could be so much better. That said, it does get a bad reputation for bad code when it is very much possible to write good code in PHP. But yes, it has huge flaws. There are more jobs in PHP where I am, however, than languages like Ruby or Python, sadly. At home, I never use PHP. Python all the way. :-)
- mkramlich 15y agoI too have a low opinion of PHP and this article was one of the best takedowns I've seen on it. Nailed it.
- eplace 15y agoPHP is the "Rudy" of web languages. It just won't quit. I remember switching to PHP for three reasons about 9 years ago. I cycled through Perl, ColdFusion, Java Server Pages, and ASP JScript before getting to it. 1. It was the most accessible free alternative to costly platforms (ColdFusion, MS ASP) or more strict / difficult to configure platforms (Perl, JSP). Error checking was as simple as ASP/JSP and starting up was as simple as paying for a cheap LAMP server that would run it out of the box. 2. It had the largest set of online documentation for both the language itself and tutorials / code examples. This was one of the biggest unavoidable draws to the language. The community was huge and still is to this day although documentation is much more evenly distributed across other languages now. 3. PHP may be one ugly beast but it does pre-package practically every piece of functionality you could ask for within it. I'm not sure I have ever liked the look of the code but there was something magical about being able to grab remote server code via file_get_contents for the first time. It was so damn easy! If I were to suggest a platform today I would probably have to go with Python. It has all of the same advantages that PHP had in the past but has the added benefit of being better designed and applicable to more than web programming. Ruby would be my second choice simply because the environment setup is a bit more complicated still, although the language is the most beautiful in my opinion.
- gosub 15y agoI was expecting an image of the radix tree of PHP function namespace.
- perlpimp 15y agoPHP has had its time FWIW gave ASP.net run for its money - and lets leave it at that. Ruby has some difficult points. There are some antipatterns in rails. What dynamic languages do really bad is error reporting. And that what makes its so damned hard to get around becoming really good at a predictable rate. I wonder if python's Django stack traces are better on errors in templates and such.
- Newky 15y agoA little off topic, but can we please stop using lines like this in articles: because computers suck They do not. Barring only the wonders of the realm of nature, computers are in my opinion one of the most wondrous things, it is a testament to Humans as to how creative, industrious and sheer genius we can be. They allow us to do computations beyond our wildest possibility, allow us to control, consume, produce and every other verb you care to mention. Computers do not suck.
- hm2k 15y agohttp://en.wikiquote.org/wiki/Rasmus_Lerdorf http://en.wikiquote.org/wiki/Rasmus_Lerdorf
- jhuni 15y agoJavaScript was rushed to the market in a few weeks so it is also a fractal of bad parts, for example, the == operator sucks just like in PHP, the + operator is used for both addition and concatenation, semicolon insertion has an unintuitive behaviour, etc. See JavaScript the bad parts for more detail. The entire web is built on a terrible foundation with languages like JavaScript and PHP that it is a wonder how it got to be as advanced as it is today.
- TazeTSchnitzel 15y agoJavaScript has its bad parts, but it's nowhere near as bad as PHP in its bad parts. JavaScript has some really good ideas in it as well. Plus, it's actually quite easy to code in JavaScript avoiding the bad parts.
- jhuni 15y ago>JavaScript has its bad parts, but it's nowhere near as bad as PHP in its bad parts. I am not familiar with any precise quantification of the bad parts of JavaScript and PHP which could serve as a basis of that conclusion. That said, both PHP and JavaScript are web scripting languages that are full of bad parts. Extrapolating outwards, the entirety of modern web development is flawed. > Plus, it's actually quite easy to code in JavaScript avoiding the bad parts. In a sense it is harder to avoid the bad parts of JavaScript because it is tied to the browser platform, with PHP you can avoid basically all of its bad parts by simply using a different language like Clojure or Scheme.
- sedev 15y agoThis is also part of the problem. Go read Crockford's "Javascript: The Good Parts". Then notice that this article demonstrates why there is not, and probably never will be, "PHP: The Good Parts."
- ericingram 15y agoI'm building a developer oriented platform using PHP. I made the decision to use PHP mostly for market size. If I targeted, say, Python or Ruby developers, my market would be too small to make a significant business. The PHP eco-system (largely made up of platforms and templates) is huge. Ignore it at the peril of your revenue.
- jordanarseno 15y agoAm I the only one who thought this blog exploded their monitor?
- tmh88j 15y agoThe one thing that really bothers me about these "PHP sucks" articles is that the author implies that it's inevitable that anything written in PHP will be complete junk. Yes, it has flaws, but PHP is associated with spaghetti code 100% of the time regardless of who's writing the code. I've seen some very well structured PHP; Yes, it does exist. I'll admit that I am new to web app development and learned how to program(web apps) with PHP. The simplicity and forgiving environment is what made it so alluring. Sure my first bits of code may have been sloppy, but that sense of false confidence pushed me to learn more and improve my understanding. I gained experience and "real" confidence quickly. After seeing how easy it was to make simple apps with authentication features and whatnot, I moved onto Python. PHP quickly taught me the basics which then allowed me to jump into more advanced features and other languages, and that is why I appreciate it. Before anyone uses my words against me where I mentioned a sense of false confidence, I think that's actually a positive thing. It pushes the user to learn more, or at least it did for me. Do you really think anyone with a complete lack of understanding of OOP, frameworks, or programming in general will be able to hack together a Facebook, ebay or Paypal?
- wvenable 15y agoMost PHP frameworks are very well written -- their code is out there, on github, for all to see. There is a lot of well written PHP code. But there is also a lot more PHP code written, in general, than other languages especially by non-programmers.
- corford 15y agoI'm not qualified to refute many of the programming points in this article but I can say that this is wrong: "Similarly, there is no easy way to “insulate” a PHP application and its dependencies from the rest of a system. Running two applications that require different versions of a library, or even PHP itself? Start by building a second copy of Apache." If you're running PHP via fastcgi (e.g. mod_fcgid on Apache), you can build as many different versions of PHP as you want and then point the various websites/webapps to whichever version they need. It's trivially easy to do.
- Xylakant 15y agoBut actually, then you're back to the deployment model that ruby apps used before switching to dedicated app servers and everybody said "oh, that's sooo complicated."
- corford 15y agoI'm not a ruby user so I might be missing your point but... There's nothing stopping you running php on a separate dedicated machine from the web server. You'd just use mod_fastcgi and php-fpm. You can run it in a webserver thread (mod_php), run it in its own process alongside the webserver (mod_fcgid), run it on a dedicated machine (mod_fastcgi) or run it from the command line. That's the beauty of PHP, it lets you do what you want. The downside is that this flexibility can be dangerous in inexperienced / naive hands.
- Xylakant 15y agoRight, you can do what you want, I know that. The point is: If you do it, then you're at the deployment model that rails has been using all the time and that the php people said to be way too complicated. The simplest way nowadays to deploy rails is mod_passenger. It's about as simple as it gets - dump files, reload app. Done. Actually, I don't get what's so simple about deploying PHP files individually via ftp. All I do is enter 'cap deploy' on a terminal. And I get free rollback. (there's web interfaces as well)
- scotty79 15y agoand yet it moves PHP is a product of evolution. It's not nice but it's incredibly well adapted. Instead of complaining about how ugly it is people should be researching why it flourished and make sure that they introduce the same qualities in their designed systems. I have few guesses what might these qualities be. - Script serves one request and dies. Problems are limited in time and range. They most likely won't bring your app down. - You have universal data structure, ordered dictionary with lots of functions that operate on it and some additional features for numeric keys. - you have php.net/name_of_the_function which gives you description of the function and it's parameters, return values with comments and examples of use from the users. - getting things sent by browser is extremely easy, sending stuff to browser is even easier. - if you want to do something, functions that will help you are there because someone needed that before you and just added them there. And it's not in some obscure package that you have to download from God knows where. It's in the core and it's most likely only one of it. You can dissect a rat and complain how ugly it is but it will still eat your lunch. All the elegance of other languages are not that important. 99% of software development is not architectonic cathedrals. It's telling your slave what you want from him. Also 78% of the statistics are bogus including this one.
- samlev 15y agoI know PHP is horrible, but I use it, and so do thousands of other people. Until there is something else where you can deploy a prototype by dragging a single file onto a server with a FTP program, then PHP is serving a purpose that no other language can meet. So stop crying about how PHP is horrible; stop trying to fix what is obviously a broken language; make something else that can fit this need, and you will kill PHP. The only reason why still PHP exists past hobbyists is because people who start businesses want a fast prototype, cheap hosting, and no fuss. It may not be ideal, secure, fast, scalable, maintainable, or anything else, but if it's making money in the shortest amount of time possible, with the lowest cost barriers, then it's a success.
- frederico 15y agoTL;DR stack traces? learn to throw exceptions and I'm given a very nice stack trace. complaining ftl..
- methodin 15y agoDevelopers really do complain a lot, don't they? PHP offers unparalleled flexibility if you have any notion whatsoever of how to properly develop things. Those who think otherwise are most likely stalwart proponents of some other language, engulfed in functional programming or have read the latest post by _____ that explains a concept that should be used only rarely and will use it as an attack to state why another language is awful. The fact is, you will never, ever, ever convince someone that your opinions are better than their own if they don't already think those things. Every language sucks and every language is awesome. Get over it. Bootstrap/CSS, HTML, jQuery and the database are easily 80% of the code of any generic site that isn't a business. The rest is Database access, AJAX functions, Auth, View rendering and hopefully security - and while important are very small in comparison to the grand scheme of things. You don't need sockets. You don't need Duck typing. You don't need event-driven functionality to do most of the things you find on the internet. Those things are fun, but are not that important in the long run. PHP is outdated, seemingly random and can let you write terrible code. It also does not get in your way if you are a competent developer and shortcomings are slowly being addressed, which is a good thing. When was the last time you wrote a site that NEEDED the things PHP is missing as a language?
- sedev 15y ago"It also does not get in your way if you are a competent developer..." Actually about half of the article was about how it does exactly that by being inconsistent, having action-at-a-distance effects, and not having real hashes/arrays/tuples. Also you appear to have skipped the "Don't comment with these things" portion of the article, which anticipates all of your arguments.
- soc88 15y agoIt is amusing that most people defending PHP are not able to write a coherent English sentence. Just read the comments under the article.
- tnash 15y agoWow, this article is unnecessarily harsh. You get the feeling that one of his immediate relatives was crushed in a freak industrial machine accident and that he later found out that the machine was programmed in PHP. I work with PHP everyday, and it's a fine tool. It does what I ask of it, at least. If the objective is to drive a nail into a board, you can do it with a hammer or a rock, and it doesn't really matter which. Accomplishing the goal is what matters. If you can do it in the same time, why does it matter which tool you use? So one may be more elegant. So PHP is slow as balls. Programming isn't a religion. We don't need to be so dogmatic.
- sedev 15y agoFrom the article: >Don’t comment with these things >>I’ve been in PHP arguments a lot. I hear a lot of very generic counter-arguments that are really only designed to halt the conversation immediately. Don’t pull these on me, please. :( >>>Do not tell me that “good developers can write good code in any language”, or bad developers blah blah. That doesn’t mean anything. A good carpenter can drive in a nail with either a rock or a hammer, but how many carpenters do you see bashing stuff with rocks? Part of what makes a good developer is the ability to choose the tools that work best. >>>Do not tell me that it’s the developer’s responsibility to memorize a thousand strange exceptions and surprising behaviors. Yes, this is necessary in any system, because computers suck. That doesn’t mean there’s no upper limit for how much zaniness is acceptable in a system. PHP is nothing but exceptions, and it is not okay when wrestling the language takes more effort than actually writing your program. My tools should not create net positive work for me to do. That's not even deep in the article! By spouting off exactly the arguments that the author anticipates, you're making yourself look like a jerkhole who didn't even do basic reading before spouting off a reflexive, unthought, and worthless opinion.
- deleted 15y ago[deleted]
- tnash 15y agoI did read it, that's why I used that concept. I don't think calling me a "jerkhole" really adds to the dialogue. I just disagree. The author points it out because he doesn't want to hear it. That doesn't make it a less correct counter-argument. I think accomplishing the goal is most important. Secondly, I don't think PHP is a bad tool. You can accomplish tasks very quickly in PHP. It is certainly not the fastest language, of course, it's not compiled, but it has a lot of great features. A lot of the points made in the article I consider features of PHP and are not detrimental.
- cletus 15y agoIf this one thing that annoys me on HN it's the pervasive anti-PHP snobbery. A selection from the OP: > Because of the @, the warning about the non-existent file won’t be printed. So your complaint is that when you use @ to suppress an error it... suppresses the error? > The language is full of global and implicit state. "Global" is one of those dogmatic points. Nothing is truly "global" in PHP. The "global" in PHP just means it is request-scoped (ignoring $_SESSION, which is explicit anyway). Do people complain about request-scoped data in any other language? No. The PHP haters just decide to hate this largely due to the (somewhat incorrect) label of "global". > There is no threading support whatsoever. That's a good thing. It forces you to use async HTTP programming or something like beanstalk, both of which are better than the complexity of threading. > array_search, strpos, and similar functions return 0 if they find the needle at position zero, but false if they don’t find it at all. So, it's a problem that array_search returns 0 when something is at... position 0? And returning false is just a sentinel value, much like functions in other languages might return -1. So what? > In, say, Python, the equivalent .index methods will raise an exception if the item isn’t found. I, for one, hate throwing an exception when an item isn't found. This sucks: try: index = a_list.index(a_value) except ValueError: # do something - If you use FALSE as an index, or do much of anything with it except compare with ===, PHP will silently convert it to 0 for you Yes, you have to use --- and basically understand that otherwise 0 == false. So what? In C/C++ you also have to remember to use == not -. > [] cannot slice; it only retrieves individual elements. Much like Java/C/C++. PHP has array_slice() if you want it. It's since been redacted but the OP originally claimed that Facebook doesn't really use PHP (because, hey, that fits his world view). Look, I could go on but really what's the point? Haters gonna hate. Sure it would've been nice if PHP had been consistent with, say, parameter ordering (needle, haystack vs haystack, needle) and function naming (sometimes using underscore, sometimes not) but really none of that matters. If you use it, you soon remember. Humans are built to understand inconsistent languages. If we weren't, we wouldn't be able to speak to each other. Some like to argue that PHP is a beginner's language. I disagree. I think PHP is a fine language for just throwing something together... if you know what you're doing. Otherwise it's just a recipe for SQL injection and XSS vulnerabilities. A common mistake with PHP is people try and turn it into Java with complicated object frameworks. There is typically lots of hand-wringing about OO'ness. The procedural style is actually very natural for serving HTTP requests. The core of PHP is a stateless core of API functions. This is incredibly useful for keeping resource usage down. Much like the old CGI model, the entire environment is created, used and destroyed on each request. This is a feature not a problem. Anyone who has done Java Web development (with stateful servlets or any derivative) should know this as it is virtually impossible not to have come across resource leakage and concurrency issues at some point. The stateful model, while useful, has a significant cost. I really don't understand this need to complain so vocally about something like this. Possible reasons: - It affirms the OP's sense of superiority somehow; - It's about "street cred" with [Python, Ruby, Node.js, insert other language here]; or - One is so obsessed with "purity" that one spends all one's time complaining about how everything isn't Lisp. Use it or not. I don't care. If you're not going to use it, why complain about it? If you are using it, what does the public snobbery (which is really adding nothing new to all the other PHP rants) really add? I'm a big fan of pragmatism and the fact is that 4/20 of the most visited sites on the Internet are written in PHP. EDIT: /sigh/ I get the inevitable "you must be a PHP programmer" retort (like that's actually a retort and not just more snobbery). For the record, I've only used PHP for ~6 months. My main experience is Java (~14 years), Python (~2 years), C (~5 years) and C++ (~4 years).
- robomartin 15y agoIf ~ PHP then ? Why?
- doctorwho 15y agoPHP gets a lot of hate for the same reason that Microsoft gets a lot of hate. PHP could have been rewritten from scratch and made more orthogonal but it would have immediately broken every existing PHP application out there. For better or worse, the install base matters. Once you a function/feature it's there to stay or you can't ever upgrade your server.
- lathamcity 15y ago> PHP is a community of amateurs. Very few people designing it, working on it, or writing code in it seem to know what they’re doing. (Oh, dear reader, you are of course a rare exception!) This was about when I stopped caring about what the author had to say. The sentence where he snobbishly belittled me and called me an amateur because of the programming language I use.
- wyck 15y agoWhat's worse than PHP, people that complain about it. It's like a plumber complaining about copper in lieu of plastic, no one gives a shit, just get the job done. Sitting in your little complaint hole , no matter how well thought out, doesn't really help you does it?
- fadzlan 15y agoOther plumbers might give a shit. Besides, I enjoy analysis of programming languages, the good and the bad parts.
- s0me0ne 15y agoPHP doesn't require any libraries to build a simple website. I've yet to see any document that shows in great detail (more than a simple 1 chapter static page based site) how to build a website using Ruby or Python by itself. No libraries, frameworks (no Rails, no Django) or other external stuff, just plain old Ruby or Python. I think this combined with the fact it's very easy to learn, the ton of tools out there, ton of web apps make it a hard language to kill. What really can be done? Should they make a new version that provides more consistant function names and break backwards incompatibility? I've yet to hear what people think should be done with PHP besides abandoning it. That being said I don't think it should die, I think it has it's place. I'm not as smart as the rest of the folks on here, but for doing client sites, PHP gets the job done very fast.
- optymizer 15y agoTo the OP: you, Sir, have a lot to learn, both as a programmer and as an individual.
- epo 15y agoI am deeply amused by all the PHP apologists in this thread, I assume it is an equal mix of Stockholm syndrome and people vehemently defending the only thing they (think they) have any experience with.
- joshontheweb 15y agoThe final nail in the coffin for me with PHP was when it it started giving me errors in hebrew! 'T_PAAMAYIM_NEKUDOTAYIM' wtf?
- joshontheweb 15y agoThe final nail in the coffin for me with PHP was when it it started giving me errors in hebrew! 'T_PAAMAYIM_NEKUDOTAYIM' wtf?
- digitalzombie 15y ago>>Despite the craziness above, and the explicit rejection of Perl’s pairs of string and numeric operators, PHP does not overload +. + is always addition, and . is always concatenation. I like the fact that + is for addition and . is for concat. It's kind of up in the air if you do "1" + 1, does it become a string? Or an integer?
- Kilimanjaro 15y agoPersonal Hypertext Preprocessor Nothing in the whole world is easier and faster for a 4/page Personal Hypertext Project. Nothing. Don't blame me, I use python and go most of the time, I just wanted to point out the answer to why people still use PHP today. It was created with that only purpose, it grew like weed out of control. Don't you ever compare php to python, ruby, java or haskell. Don't even try to ridicule php, the only one looking bad will be you for being so ignorant to compare a rock with a hammer and wasting a whole post complaining how the rock doesn't even have a handle.
- optymizer 15y agohaters, hate on this: time python -c "for i in range(int(1e8)):pass;" time php -r 'for($i=0;$i<1e8;++$i);' go on, run the commands.
- romaniv 15y agoI've programmed in PHP for many years and still use it for my side projects, but I would state that the criticism in the article is mostly fair and relevant. Yes, as an environment PHP is easy to deploy, fairly well-documented and has some other nice benefits (like shared-nothing architecture, build-in templating or the ability to write config files using core syntax). However, as a programming language PHP is pretty awful. Worse, the issues it has are glaringly obvious and not that difficult to fix, if you're willing to break some compatibility, which it regularly does anyway. It would be better for everyone if people could mentally separate PHP's features and misfeatures and learn from both, instead of just bashing the language and jumping to its defense as a whole.
- BryanB55 15y agoI'm no programmer. I'd consider myself more of a designer and marketer. But I plan on creating a SAAS app soon and I was planning to use PHP for one main reason in that our billing system will be PHP (WHMCS) and our CMS will be php (WordPress). I think this is one of the advantages of PHP in that there is a lot out there already created in PHP. Is PHP really this bad that I should consider using something like ruby instead? My worries are finding good talent that want to work on a custom php application a few years down the road when we expand. And of course I'd want to be more likely to prevent bad code and build something that will be future proof. Thoughts? How screwed are new companies that start building php applications today?
- marizmelo 15y ago300+ comments... seriously? PHP is a language with problems like all others (c, java, python, etc). It can be used for good or for bad like any other programing language. All the problems on the article are well known by decent programmers. PHP is out there, use if you want. Go write decent code... stop nagging.
- soc88 15y agoWhat a useless parade of hand-waving. If you actually read the article, you knew that one of the author's point was that PHP's problems are magnitudes of magnitudes worse than other languages in the wild. That's more or less a matter of fact and that there are still people deny it just shows the sad state of PHP "programming" in general.
- HerroRygar 15y agoEveryone is certainly entitled to their opinions, but I'm puzzled as to whether some of the people claiming that PHP's greatest strength is its deployment model have had significant PHP experience? As with most things, it's both good and bad. It IS fantastic that you can so easily toss a .php file into a directory, make a few minor Apache config adjustments, and BAM - dynamic website behavior. ...that's also a glaring weakness, though, when a complex application is developed without the structure imposed by other tools. I have to maintain an event registration system written in PHP, and I'm having incredible difficulty with it. The logic to store form data, look for errors, display the current form, and prepare the form for submission are all in a single, 1000+ lines spaghetti-code file. I think the author's point (and certainly the one I'm making) is not that this is the only possible outcome of writing in PHP, or that other languages do not have this problem. Rather, the point is that the lack of cohesive structure removes barriers to writing bad code; in fact, it makes it (initially) easier than writing good code.
- webjprgm 15y agoIf it makes OP happy, I'll admit that PHP is a bad language. He certainly has the proof to back it up. But for me, I'm sufficiently used to those idiosyncrasies that I still use PHP for quickly tossing up a small site/app without the need to configure Ruby or Python web framework stacks. Maybe I'll switch eventually, but PHP still works for me and nothing else that I have tried quite replaces it in it's niche in my arsenal. (I also use Ruby on Rails and Node.js, haven't tried any Python web framework. I've used both Apache and Nginx.)
- pknerd 15y agoIt sounds more a religious war than actually talking the weaknesses and potential
- languagehacker 15y agoI wrote this satirical response to try and point out the absurdity of developing a laundry list of the things you don't like about a language: http://news.ycombinator.com/item?id=3824703 http://news.ycombinator.com/item?id=3824703
- fpp 15y agoMy 5cents on that (recently published issues): <? if ('9223372036854775807' == '9223372036854775808') { echo "I can not count!\n"; } ?> (see https://bugs.php.net/bug.php?id=54547 https://bugs.php.net/bug.php?id=54547) or built-in PHP web server dies with a large Content-Length header value: The value of the Content-Length header is passed directly to a pemalloc() call in sapi/cli/php_cli_server.c on line 1538. The inline function defined within Zend/zend_alloc.h for malloc() will fail, and will terminate the process with the error message "Out of memory". (see https://bugs.php.net/bug.php?id=61461 https://bugs.php.net/bug.php?id=61461) Luckily we are getting Javascript ready to replace all PHP on the server sooner or later ;-)
- anuraj 15y agoIf we really need neat, clean implementations, why not avoid scripting languages altogether and go for structured, type safe languages? The developer needs to be much more learned and experienced, but in the end would the code will be high quality. But the fact is web needs cheap, fast implementation. No time to crib about warts and all. All web languages are results of duct tape mentality!