6 ms·
Why so much hate for PHP?
PHP is the first dynamic scripting language I learned and have been using it ever since. Facebook uses it. Can someone explain what it's issues are and any suggest any comparable alternatives? Thanks!
- njharman 13y agoPHP is the lowest common denominator. PHP is the ghetto. It might be fun or necessary when you're young and can't afford better. But, eventually people who are able, move somewhere they aren't being mentally stabbed in the face every time they pop down to the corner store. This, of course, reinforces the ghetto. As the people who can't leave are the dregs. Nothing is as black and white as a couple sentences makes it sound. But, that is the place PHP has (deserved or no) in the programming world.
- MAGZine 13y agoA quick dive into any PHP-related topic on HN should yield significant answers. Part of the hatred comes from the fact that the way people know PHP is from 2005, when it was essentially one really long procedural program. It's not so much that people ignore the recent upgrade in tooling/modern language constructs so much as people aren't familiar that they exist. However, these is still a lot of vitrol for PHP. Because it is so easy to use, many people are able to pick it up without any prior SE experience--these people tend to create poorly-designed, slow-running, and, perhaps worst of all, dangerous (vis a vis security) code. The other major complaint that exists has to do with inconsistency/insanity in PHP's function signatures/naming/evolution. For example: mysql_escape_string and it's sister, mysql_real_escape_string. Although, anyone working with modern PHP probably will never touch these functions. What is overlooked is that it has an extensive base of developers, it DOES scale (this is proven), and the language is improving (as well as the tooling (PHPUnit, XHProf, CI tools), frameworks, package management etc). And although Facebook does use it, it's important to note that, AFAIK, PHP only exists as a thin layer in between "display HTML" and "communicating with backend servers which are going to handle the majority of the work, save for presentation-layer type stuff." There are a few alternatives to PHP, but they each have their warts too. Ruby is hilarious slow, for example.
- drjake 13y agoThanks so much for your time! I was wondering whether you would suggest using PDO or mysqli for connecting to mysql via PHP?
- LDN 13y agoFrom my personal experience I would suggest working with PDO. It is easy to implement, supports multiple drivers if needed and has named parameters in your prepared statements. The difference in terms of performance should be insignificant - although I think in some cases mysqli tends to execute faster.
- cafard 13y agoIt also has the merit for Perl developers of being more or less like Perl's DBI.
- nthj 13y ago> Ruby is hilarious slow, for example. [citation needed]. Also, relevant Stack Overflow debate is available. [1] TL;DR: yes, of course Ruby is slower than, say, C, but today's bottleneck isn't hardware, it's developer productivity. (Developer time costs way more than hardware.) [1] https://stackoverflow.com/questions/2529852/why-do-people-say-that-ruby-is-slow https://stackoverflow.com/questions/2529852/why-do-people-sa...
- skywhopper 13y agoDepends on the task. Most of my programming is on the sysadmin side. So automation and log processing are two of the biggest things I deal with. I love Ruby to death. I'd program in it all the time if I could. And it works really well for automation. But for processing massive amounts of data? Not so much. I even did some tests a year or so ago when I was writing a script to merge together data from multiple log files and a couple of databases, including data transformations, merging/collation and sorting of, oh 100GB or so of raw log data a day. My first tests with Ruby were running pretty slow, so I decided to write the script out as I'd planned in both Ruby and Perl and compare the results on subsets of the data. I used none of Ruby's OO features, I just did straight simple data structures, hashes and arrays, etc. Ruby has far better infrastructure for dealing with these things built in, and so I wrote the Ruby script in a couple of hours. The Perl script took me a couple of days--admittedly my Perl is rusty, but I wasn't doing anything complicated. But the language just doesn't have as much stuff built in. Anyway, at the end I had two scripts with exactly the same logic, and I'd even had to implement some things (like Ruby's Array#uniq, which I assume (but don't know) is written in C) from scratch in Perl. So yeah I wasted 16 hours on the Perl script, but you could follow them line by line and they were identical. Run them one after the other to compare, and the Perl script is literally 100 times faster and uses a tenth of the RAM. I told my Python-loving friends about this and they guffawed at the silly Ruby guy, but it was depressing. So yeah, Ruby is slow at runtime compared to other languages. Usually that doesn't matter, but sometimes it matters a lot.
- 27182818284 13y agoEssentially because it wasn't a well-thought out language, but a hack, it became used widely, but that lack of thoughtfulness shows on larger projects quite a bit. It is a hack that need to become more formalized with time, but it hasn't quite done that. Whenever I still see "needle" and "haystack" in documentation I think "Wait what is this? Oh right..." >Facebook uses it Not really, I mean Facebook doesn't use the PHP that a common person uses.They've made so many changes and their codebase is so huge. Facebook also uses the D programming language, HipHop, and probably more tools than I'll ever know. Wasn't chat at Facebook first written in Erlang?
- natmaster 13y agoFurthermore, the only reason Facebook stuck with php and made massive changes to make it somewhat usable is because of its huge legacy codebase. They would have much rather be working in a different language these days.
- deleted 13y ago[deleted]
- wcummings 13y agoI assumed they use ejabberd, or some modified version of it, I'd be interested to know if they built their own erlang chat-server in-house.
- lawl 13y agoI could write something here. But someone has already written a pretty comprehensive post on what's wrong with PHP. So I'm going to refer you to that. PHP a fractal of bad design: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de...
- deleted 13y ago[deleted]
- skywhopper 13y agoPHP does what it does relatively well, but it's a quirky muddle of a language and its design is very tightly bound to a CGI-style model of web development. Anything can be hacked around, of course, as Facebook has proven. But you could write Facebook in Bash or DOS Batch Language if you were willing to. But newer frameworks and languages that were designed with modern web development in mind are more to a lot of people's liking than PHP's style. Really, the best way for you to answer your question is to dig in and learn how to develop a webapp using Ruby or Node.js or Python and the amazing frameworks that are built on those languages. Dig in for a couple of years and then on the other side you'll understand better. You may still prefer PHP, but even if you do, I'll bet the PHP code you write will be better for having learned how the "other guys" do things.
- moreentropy 13y agoThere are a lot of reasons already discussed, this one is especially famous: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de... PHP is not a exceptionally bad platform from a technical perspective, it usually gets the job done, is reliable, easy to operate and performant. But i guess the real reason why so many developers - including me - hate PHP is that plain PHP is pretty boring. It doesn't have opinions on anything and no exciting concepts or language features. Now you can use great frameworks that implement great ideas in PHP, but because PHP has been around for a long time, much of the code out there and still in production is spaghetti code that is no fun to work with and the only option to change that is often a complete rewrite.
- feydaykyn 13y agoThe CodingHorror blog have been quite vocal on the tour too : http://www.codinghorror.com/blog/2012/06/the-php-singularity.html http://www.codinghorror.com/blog/2012/06/the-php-singularity...
- dionidium 13y agoThe problem with Jeff's writing isn't that he ever says one big thing that's just obviously wrong, but his pieces are full of bits that just sort of don't make sense. Remember the immediate visceral reaction you had to the double-clawed hammer? That's exactly the reaction most sane programmers have to their first encounter with the web programming language PHP. First of all, I didn't have a visceral reaction to that image (and I'm not sure Jeff knows what that word means), but setting that aside, the second sentiment is just wrong. PHP doesn't cause that reaction on your first encounter. Most of its ugliness is in a bunch of little things that you learn to deal with over time. Another example. He says: What we ought to be talking about is not how terrible PHP is – although its continued terribleness is a particularly damning indictment – but how we programmers can culturally displace a deeply flawed tool with a better one. How do we encourage new programmers to avoid picking up the double clawed hammer in favor of, well, a regular hammer? And in the very next paragraph: Despite the serious problems with PHP, I was forced to consider it. If you want to produce free-as-in-whatever code that runs on virtually every server in the world with zero friction or configuration hassles, PHP is damn near your only option. I don't know how he doesn't think that contradicts his previous point. Actually, now I'm not even sure what his previous point was. Inexperienced programmers are wrong to choose PHP. But, also, PHP is the best choice available. I won't go paragraph by paragraph, but these things really add up when reading his writing.
- vezzy-fnord 13y agoSeveral reasons, I think. For one, it's no secret that PHP was an amateur undertaking that inadvertently ended up powering >80% of the web. It started off as a bunch of helper functions that were meant for Rasmus Lerdorf's personal use. He has frequently acknowledged that he was never particularly skilled and that PHP was never meant to be used on such a large scale. Among the countless WTF moments you would expect from a personal project, PHP once used strlen() as a hashing function. [1] Thus, PHP ended up having a very inconsistent design and an awful typing system. It ended up becoming quite baroque, it has never had a formal specification and it has no coherent idea of what it wants to be. This is exemplified by PHP's relatively recent appropriation of Java idioms in an attempt to bring vague Nygaard OOP. Third, it's fundamentally a templating language and it doesn't encourage any cohesive design patterns or practice. Most PHP sites don't even use frameworks, but rather go with the Mozart (or rather, spaghetti) style of copy-paste programming. There is no clear separation of concerns. Fourth, the PHP community has always been dominated by amateurs. I can't really direct you to any objective statistics, but in general PHP has a disproportionately high amount of leechers and newbies, largely because it has been so deeply ingrained into the public consciousness as the de facto language of the web, without knowing of the better designed general-purpose alternatives. Fifth, some concrete examples of PHP's horrific internals. [2] [3] [4] Alternatives? Anything, really. Python, Ruby, Perl, Common Lisp, Haskell... whatever floats your boat. A minimal web framework is a trivial application to write. That's why there's so fucking many of the goddamned things. [1] http://news.php.net/php.internals/70691 http://news.php.net/php.internals/70691 [2] http://www.phpwtf.org/ http://www.phpwtf.org/ [3] http://www.phpsadness.com/ http://www.phpsadness.com/ [4] http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de... (the famous article)
- natmaster 13y agoTL;DR: Because we used it. Like many people, many years ago I learned php. It was easy to deploy, and make simple dynamic websites. Many hosting services provided support for it. I was quite happy to use it for these things. Then in 2008 I interned at Facebook. At the time, there had not yet been any attempts to improve the language by Facebook itself. Using php in an actual codebase - real world software - made me realize just how terrible it was. I vowed to never use it again. I even presented some of the worst aspects of php in my intern presentation to the executive team. Mark was quite intrigued. At the time there were talks of how to deal with many of the problems, but nothing had been figured out by time I left. Its deficiencies are too numerous to simply list here, so I'll give you a high level summary (which many have also said similar things). Php is a giant hacked language originally not designed for real software and then features added on. It's syntax is the worst of any used language; it's language features are severely lacking; its implementations are contradictory, confusing, and destructive. In short, it is not easy to read, it is easy to shoot yourself in the foot, it is not able to scale both in complexity and performance; and its libraries are a mess.
- jnardiello 13y agoI keep reading always the same things from people who simply don't know how to use it properly and feels hurted by a different-than-what-studied-at-school syntax.
- natmaster 13y agoStrange, I learned php before I ever went to college. By time I went to university I knew 11 programming languages, so I don't think this applies to me.
- jnardiello 13y agoMh, not sure what you mean here. As you know 11 programming languages, you might be aware that "knowing your tools" is always valid and goes far beyond syntax itself. PHP is as capable as complete as any other language. Reasons behind most devs "hate" are mostly minor things and mostly a matter of taste.
- neduma 13y agoDon't forget the epic php bashing post - http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-de...
- krapp 13y agoDoes no one who posts this in PHP threads even bother to check if it's been posted like three or four times already?
- squirejons 13y agoHomo sapiens is evolved to ingest, internalize and re-propagate ideas. That was our survival advantage on the savannah hundreds of thousands of years ago; that was how we out-competed other species using our big brains to carry out complex, improvised plans. But that evolved trait now can be seen in how we conform to the ideologies and groupthinks of political tribes and groups. Homo sapiens seeks out tribes and discerns their ideologies and internalizes them and then re-propagates. We are a species of ant-like primates, and instead of spraying chemicals or from musk scent glands, we spray ideology, the ideology of our adopted tribes. The elite use this evolved trait of propaganda-ingesting in order to manipulate us. Anti-php is one of the central tenets of HN ideology. To be a full member of the tribe you must internalize and re-propagate this ideology.
- drakaal 13y agoPHP is AWESOME! Because there are so many examples of how to do everything. If you are building a web app you need HTML anyway , and since PHP is like 75% knowing HTML you are a long ways to knowing how to do things. PHP is fast enough for 90% of websites. LAMP is a commodity you can get any hosting provider to set you up in seconds. PHP is SUCKY! Because it is way to slow for 10% of websites. 90% of coders pieced together their solutions from a mish-mash of code examples they found on the web. HTML is just strewn through out because most people do their PHP inline with the HTML rather than populating variables to output all at once. LAMP has the word Apache, and MySQL in it and that means you inherit some badness that is being sold as a commodity (yeah you can run on a non-lamp but very few who do PHP do, and so you may not be compatible if you stray from LAMP which means you are writing in a non-standard way)
- twunde 13y agoThere are a number of reasons why PHP is so disliked by outside communities including but not limited to MAGZine's points. 1) As mentioned there are a number of language inconsistencies, much more so than comparable languages. This includes naming schemes for functions 2) PHP and most major projects written in it are insecure. Even up-to-date Wordpress installs are vulnerable to attacks. 3) Testing still isn't in vogue. Few projects have any testing and for those that do the testing tools aren't nearly as strong as in other languages 4) The tooling that surrounds the ruby, python, go, javascript languages is much more advanced than what PHP has even now. PHP only really got a decent package manager last year. 5) For a long time most PHP projects were procedural. Real OO was only introduced in PHP 5. 6) There is a lot of bad code written in PHP because it was so accessable. 7) Most examples of PHP projects are CMS' which don't require a ton of experience to build. You meet a lot of people who have spent 10 years in the industry that really have just managed content that don't know how to build something complex and don't have any background in data structures, algorithms etc 8) The PHP community is extremely fractured. There are something on the order of 10+ major PHP frameworks. Zend, Symfony, Codeigniter, Cake, Laravel, Kohana, Yii plus a number of more minor frameworks like Lithium, Silex etc before you get to the CMS' like Joomla, Wordpress and Drupal
- crazytony 13y agoNumber 3 is the reason we moved our last PHP "backend" to Java ages ago (2006). I'm surprised it's the first mention I've seen of it here.
- twunde 13y ago2006 was a while ago. Testing is still not expected in PHP but the modern frameworks have testing available even if the culture surrounding it is rather weak.
- padraicb 13y ago1) Agreed. 2) Citation? PHP is extremely popular so it has more insecure code in comparison to Ruby. Also Rails isn't above multiple security vulnerabilities per year so I don't see how Wordpress (which incidentally is an extremely old application) could be. 3) Testing is extremely popular these days. It's 2014, not 1999. 4) Agreed. PHP finally got shut of PEAR and Composer has had an unbelievable impact on PHP. 5) PHP 5 was released 10 years ago. Give it up already about procedural code. 6) Agreed. 7) Not my experience. 8) PHP has a massive community. Ergo, it has a long tail of frameworks. I seem to remember that Ruby has had more than one.
- jnardiello 13y agoIMHO, PHP is hated and misconsidered because: Since a few years ago, it was mainly used by amateurs. The truth is that PHP, right now, is a very appealing and competing language. I know several companies that power their services with PHP and it just makes wonders. Of course: you need to know what you are doing. But the language itself is capable of doing almost everything, without drawbacks. Lot of people make clueless claims about how PHP is worst than (place-latest-cool-framework/language-here). This is far from being true, read this: http://philsturgeon.co.uk/blog/2013/11/benchmarking-codswallop-nodejs-v-php http://philsturgeon.co.uk/blog/2013/11/benchmarking-codswall... So, PHP is hated in the devs world because it gave access to "amateurs" to the world of crafting software. Which is ridiculous.
- cafard 13y agoI think that it is great that "amateurs" have a usable tool. I did have a grudge against PHP, derived from having maintained a system written in that fashion. Do I really care one way or another? No.
- paulgb 13y agoThis is a few versions old, but here's a graph I made showing which values PHP considers "equal" https://www.dropbox.com/s/dgymauqggtyurvp/phpeq.png https://www.dropbox.com/s/dgymauqggtyurvp/phpeq.png
- deleted 13y ago[deleted]
- cnlwsu 13y agoThe more a language is used the more its hated. The ones everyone complains about are most likely to be the ones you will use to make money.
- artificialidiot 13y agoThere are two kinds of languages, those no one uses and those everyone bitches about.
- blantonl 13y agoHere is why. I like to equate the technical community with the skiing community. The barriers to entry are tough. It takes a lot of practice to become good skier, and many that do become expert skiers instantly elevate themselves above the rest with routes, equipment, and other types of "I'm more technical than you." So, back to hate for PHP. The C++ and Clojure and Erlang crowd are the double black diamond skiers, and they are the first to throw hate at the green and blue skiing crowd - because, well, they've mastered everything else and since they mastered it, well, they are just better than you. Meanwhile, you've got the PHP type skiers who are cruising the groomers, enjoying the sun and living life - pinching themselves because they are just getting the task done. They occasionally hit a black or two, and even hit the moguls to refine their turns and technique, but they are there to get shit done - which means to ski and have fun. Then you've got the Perl and COBOL guys who just ski around the mountain and complain about all of the above, since they've been skiing for 40+ years. Disclaimer: I am an avid skier and maintain a number of successful Web properties based on PHP. And I love the groomers...
- mappu 13y ago$foo = []; $foo[$userSuppliedString] = 'foo'; foreach(array_keys($foo) as $userSuppliedString) { if (! is_string($userSuppliedString)) { die("I understand all the reasons for this behaviour, but it violates the principle of least astonishment"); } } Supply a string. Works fine? Try running with a string that looks numeric. I use PHP every day, it's a great language for many things including teaching programming. Every language has its quirks and i don't really think PHP's quirks are worse than others. "The Tao gave birth to machine language. Machine language gave birth to the assembler. The assembler gave birth to the compiler. Now there are ten thousand languages. Each language has its purpose, however humble. Each language expresses the Yin and Yang of software. Each language has its place within the Tao - but do not program in COBOL if you can avoid it."
- viraptor 13y agoSince everyone concentrates on the development side, let me just leave a note from actually hosting php: A standard, no crazy stuff, database-backed blog+login site made in Symfony consumes ~60MB of memory. Then discards it and starts again. On each request. Even if the bytecode itself is cached, it has to create/register all the classes and global objects it uses every single time. I think people should find that at least weird and probably scary. Other languages, which separate continuously running application servers from the page serving, do not do that.
- MAGZine 13y agoIt has it's positives and negatives. If you tell a room full of Java and C++ developers with no experience to PHP, that on every request, everything gets loaded, and at the end of the request, everything (and I mean everything) gets torn down, you'll get a bunch of blank stares. However, the web, in its nature, is stateless. So, having a language where nothing persists across requests (except that which you store/retreive by using cookies/session data) is suited to the web. Also, not having to worry about memory management or thread-spawning helped to make PHP the simple, accessible language that it is. No memory leaks!* ;-) In loadtesting, I've found that PHP is almost always CPU bound. Yeah, you might be loading and unloading 60MB of memory each time, but a) caching (send those 304s!) and b) it's not like your memory is going to 'go bad' from loading/unloading Symfony. That said, there might be something to keeping Symfony loaded in memory. In my own tests, loading the classmap is one of the longest-running tasks in simpler PHP applications.
- deleted 13y ago[deleted]
- kazza 13y agoIt is popular, ubiquitous, easy to learn, feature-rich, stable and fast. By ubiquitous you may infer easy to find developers and server hosts for.