
Why so much hate for PHP? - drjake
PHP is the first dynamic scripting language I learned and have been using it ever since. Facebook uses it. Can someone explain what it&#x27;s issues are and any suggest any comparable alternatives? Thanks!
======
natmaster
TL;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
I 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.

~~~
Niten
Well for what it's worth, I keep reading _that_ from people whose exposure to
programming languages and techniques is limited to making LOB applications in
PHP and maybe one or two other lowest-common denominator languages. Most
people I know who have any real breadth of programming experience find PHP's
language deficiencies glaringly obvious, even if they find it occasionally
useful due to deployment requirements, etc.

But more to the point, if anybody knows how to use PHP properly I'd think it
is somebody who has worked at Facebook, and you can't just dismiss natmaster's
complaints with hand-waving that he must not have been doing it right.

~~~
jnardiello
> _if anybody knows how to use PHP properly I 'd think it is somebody who has
> worked at Facebook, and you can't just dismiss natmaster's complaints with
> hand-waving that he must not have been doing it right._

Well, considering the scenario he described in his own post, it's obvious that
PHP wasn't used in the right way. Working at facebook itself, unfortunately,
means nothing as i have no idea how their code _actually_ is and what
natmaster was doing there.

> _Well for what it 's worth, I keep reading that from people whose exposure
> to programming languages and techniques is limited to making LOB
> applications in PHP and maybe one or two other lowest-common denominator
> languages._

For what is worth, i've seen PHP applied with different patterns and
architectures in scenarios that were pretty wide, powering millions of
contacts daily. It's probably because of this that i learnt that it's actually
a well-done language whose only fault is that it isn't popular among engineers
and mostly used by amateurs. But this has nothing to do with the language
itself.

~~~
1010011010
PHP is not well done. Even its creator agrees.

------
MAGZine
A 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.

~~~
nthj
> 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-
sa...](https://stackoverflow.com/questions/2529852/why-do-people-say-that-
ruby-is-slow)

~~~
VeejayRampay
Been a Ruby programmer for 5 years now and I find that this is dodging the
issue. Sure the productivity is higher but what happens when you're finished
developing and your code is now running in production? What happens when it's
slow at serving requests, slow at any form of computations, slow when a rake
task is starting?

Talking about productivity is a good thing because raw "power" doesn't mean
anything, but I really wish we could admit publicly that Ruby is really not a
race horse. It does other things awfully well and I wouldn't trade language
for the world, but man, I wish it could get a free speed jump like Javascript
got a few years ago.

~~~
tomphoolery
There have been some steps in that direction, it seems. At my company, we made
a graphics rendering engine in Ruby (haven't released it yet). In testing, it
ran steadily, but consumed a lot of resources. But in each new version of
Ruby, we saw that resource usage go down. Given that same level of innovation,
we will see this graphics engine reach similar speeds as our current, more
performant C and Lua implementation eventually.

Ruby 2.0 and 2.1 made incredible improvements to the garbage collector, a
major source of our problem. We determined that it was the speed at which we
were creating and destroying objects that was causing the GC to work on
overdrive, which drove up CPU usage. So with the new GC improvements, we saw
that usage go further and further down.

------
moreentropy
There 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-
de...](http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/)

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
The CodingHorror blog have been quite vocal on the tour too :
[http://www.codinghorror.com/blog/2012/06/the-php-
singularity...](http://www.codinghorror.com/blog/2012/06/the-php-
singularity.html)

~~~
dionidium
The 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.

------
twunde
There 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

~~~
padraicb
1) 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.

~~~
twunde
2)Within the past 6 months I had a wordpress install, which was up-to-date
used in a DOS attack against someone else. PHP also does some surprising type
changes that can be exploited. That plus people remembering the
mysql_real_escape crap leaves people with a poor impression of PHP security.

3) It's definitely much better but still doesn't compare to the ruby or node
communities. I think the biggest changes to the community will be a bigger
focus on testing/TDD and facebook's HHVM

5)True. Wordpress and Joomla are extremely old applications. However Wordpress
is still extremely popular, which is why I bring it up.

7) Would you mind adding what your experience has been? I'm genuinely
interested.

Ruby really only has 2 main frameworks: Rails and Sinatra. Python and Node are
more fractured, but there are generally a few main frameworks

------
27182818284
Essentially 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
Furthermore, 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.

------
vezzy-fnord
Several 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-
de...](http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/) (the
famous article)

------
paulgb
This 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)

------
skywhopper
PHP 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.

------
jnardiello
IMHO, 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-
codswall...](http://philsturgeon.co.uk/blog/2013/11/benchmarking-codswallop-
nodejs-v-php)

So, PHP is hated in the devs world because it gave access to "amateurs" to the
world of crafting software. Which is ridiculous.

~~~
cafard
I 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.

------
blantonl
Here 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...

------
lawl
I 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-de...](http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-
bad-design/)

------
mappu

        $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."_

------
drakaal
PHP 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)

------
neduma
Don't forget the epic php bashing post -
[http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-
de...](http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/)

~~~
krapp
Does no one who posts this in PHP threads even bother to check if it's been
posted like three or four times already?

------
viraptor
Since 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
It 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.

------
njharman
PHP 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.

------
kazza
It is popular, ubiquitous, easy to learn, feature-rich, stable and fast. By
ubiquitous you may infer easy to find developers and server hosts for.

------
cnlwsu
The 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
There are two kinds of languages, those no one uses and those everyone bitches
about.

------
squirejons
Homo 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.

