
PHP Sucks But I Like It - ircmaxell
http://blog.ircmaxell.com/2012/04/php-sucks-but-i-like-it.html
======
api
The secret to PHP's success is simple. I've never seen anyone point it out.

It just works.

If you have a web server configured to run PHP, then it's ridiculously simple
to get a page to execute. Just put a .php file on the site and it runs. Done.

You don't have to jigger a bunch of components, dink around with a bunch of
Tomcat or Ruby on Rails or proxy or other annoying settings. Most other web
execution environments have a bunch of Rube Goldberg machine components you
have to plug together to get them to work. It also performs very well and
supports a lot of things.

~~~
Lazare
True. A lot of webhosts are configured such that you can drop some PHP files
into a directory via ftp, and it'll "just work". Which is nice. But...

...that's not really inherent in PHP. You can configure Python to be just as
easy, and some webhosts do this. Node is pretty much always this easy. Django
and Rails can also be this easy (if you've ever used Webfaction, you'll know
what I'm talking about).

And, on the flip side, if you want to install configure PHP yourself, it's
actually not that easy. It's trivial to get a PHP page to execute given a web
server configured to make it trivial (but, again, that's true for almost any
language), but configuring the web server isn't trivial.

~~~
CJefferson
PHP's hello world, for transmitting back to the user, is:

<?php Print "Hello, World"; ?>

I can wrap that in a little HTML, to get valid return to the user.

I don't know what Node.js's hello world looks like. From google it looks like
the following. This is a heck of a lot more things to understand.

// Load the http module to create an http server. var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests. var
server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello
World\n"); });

// Listen on port 8000, IP defaults to 127.0.0.1 server.listen(8000);

// Put a friendly message on the terminal console.log("Server running at
<http://127.0.0.1:8000/>);

~~~
Lazare
Actually, you'd probably want Express.

    
    
      var app = express.createServer();
      app.get('/', function(req, res){
          res.send('Hello World');
      });
      app.listen(3000);
    

That is, admittedly, longer than PHP but it's arguably easier to understand
what's going on, much easier to modify and extend, and just as easy to copy
and paste off the web.

For Sinatra:

    
    
      require 'sinatra'
      get '/' do
        "Hello World!"
      end
    

Again, does PHP have any real advantage here? Python solutions will be
similar. And in all those cases we can turn this into a full app with only a
few more lines.

Consider this example of a completely function blog:
[https://github.com/mitsuhiko/flask/tree/master/examples/flas...](https://github.com/mitsuhiko/flask/tree/master/examples/flaskr)

There's 76 sloc of code in the blog app, plus tests, templates, database
access, and more. And it's clean, clear, and simple. What does the PHP
equivalent look like?

Of course, PHP is still shorter for hello world...mostly because it's running
as a CGI app. This is a terrible, archaic idea for all the reasons that get
discussed when people talk about Why PHP Is Terrible, but nothing is stopping
you from configuring other languages that way. So here's a real apples-to-
apples comparison:

Python:

    
    
      print "Hello world!"
    

Too long? Try Ruby:

    
    
      puts "Hello world!"
    

19 characters including white space? Beat that! :)

~~~
greggman
No they aren't easier to understand, not by a long shot.

Imagine you're some mom who's made a static website for some group you're a
member of. You made 20-30 static pages with Frontpage or something like it.

It's a much MUCH smaller step to rename a file .php and add

    
    
        <?date('Y-m-d')?>
    

Than it is to wrap your head around what that node JS or python is doing.

It's exactly that integration that makes PHP win. If someone would make a
similar integration for a better language (and made it fit the other niches
that PHP fits that nothing else does) they'd stand a great chance of changing
the world.

The problem is, no one gets it. Just like you you're fundamentally missing
what people like about PHP. It's not the language that they like. It's that
it's HTML+server scripting. No setup needed, no external files needed, no
libraries to learn, no security issues at least at the start. It just works,
in small increments above the level of static HTML.

~~~
JohnnyFlash
Adding: <?date('Y-m-d')?>

Would whiff...

Either short tags would be disabled and cause an error. Or nothing would
happen.

<?php echo date('Y-m-d')?> \-- Would be most preferable.

<?=date('Y-m-d')?> \-- Won't work on half of webservers.

PHP is simple but most PHP servers are terrible. Part of my job is to ensure
the smooth installation of proprietary software on around 1000 servers a year.
This is the painful part of PHP development. If the client is paying less than
$5/mo for hosting then I often run into problems with misconfigured servers,
common features being disabled.. hell.. shit not working! Why isn't it
working? I don't know. There are no errors. There is nothing logged... yet for
some reason the session only lasts 7 seconds before disappearing.. yay!

I love PHP because it is simple and just works... I really dislike 80% of
shared hosting providers who cause all sorts of problems with what should be a
simple cross platform application.

~~~
alanh
Surely you realize that PHP is alone in having vast swaths of its _common
functionalitity_ disabled by hosts because of massive security problems
arising in actual use?

This means _PHP being crippled on many servers is PHP’s own fault._

~~~
wanderful
Not necessarily. Popularity makes something more likely to be exploited.
Compare PCs to Macs re: viruses. Also, many security issues were due to
conventions in early versions of the language, e.g. register globals.

------
mortenjorck
PHP is like living in a big city. There are all sorts of things wrong with it,
like homelessness, noise pollution, traffic, bad neighborhoods, corrupt
politicians, perennially-under-funded public transit; the list goes on.

And yet there's nowhere like it. You could move to some ideal community
somewhere, and maybe you visit there now and then because it doesn't have all
those other problems, but all the arts and culture, all your favorite
restaurants and bars, all the meetups and hangouts and friends and co-workers
make your city worth the downsides.

~~~
brendn
I like your city analogy. I won't stoop to comparing programming languages to
actual American cities, but I would counter that "PHP is like living in [a
particular] big city."

Here's where I disagree: it's not enough to say "hold your nose around these
parts, but it's OK because those few blocks on Main St. are worth it."

There will be flaws in any city, and sometimes due to mismanagement, the flaws
will be neglected until blight sets in. Here's where the citizens of the city
need to step up: they either flee the city and it continues to decay, or they
acknowledge the flaws and address them. _Don't just accept the downsides!_ Fix
things. Make improvements. The city only thrives on the investments of its
citizens.

~~~
Kilimanjaro
I've always said somebody should fork php and polish it, getting rid of all
the backward compatibility issues and leaving intact the ease of use and
deployment. It is unbelievable to me how nobody sees the huge potential it has
in books, blogs, docs, frameworks, etc. Like giving php a second chance, this
time done right.

Rasmus himself should give it a try as a side project with a different name. I
would follow him from day one.

PHP has a lot of bad parts and, like javascript, is asking for its cup of
coffee. The time is ripe.

~~~
fs111
what holds you back?

~~~
Kilimanjaro
Right now I am learning about compilers because if nobody does it, I will.

There are three opportunities right now in front of our eyes we are all
missing: a simpler-than-node JS on the server implementation, a rectified php,
and a simpler functional language for web development. Bonus point: a
universal templating system, like jinja, for all programming languages.

As soon as I finish the course about compilers I'll jump head first to try to
solve them all.

~~~
grogs
Is mustache.github.com not good enough as a universal templating language?

I don't agree with ever design decision made for the syntax, and I've not used
jinja, but it has the universal part handled quite well.

The idea of a roasted PHP is interesting. It's not a no brainer in the way
CoffeeScript is though. There's no real choice of language in the client-side,
but there is on the server side.

Server side devs can just learn ruby/python/.NET/Scala. Client side devs are
probs best switching to JavaScript or something very similar.

~~~
Kilimanjaro
Mustache is good enough and seeing it ported to so many languages is cool. But
I don't like it, I'll explain why:

I rather see a 'for' statement than imply that an object is 'loopable', or an
'if' instead of guessing if the var is boolean.

I rather see a differentiation between statements and variables like {%
statement %} {{ var }} like in jinja.

I don't support the idea of logic-less templates. Everything in the right
measure. Not a full-fledged language inside the template but basic loops and
conditions I think are ok.

I am always complaining about syntax but I believe if it is too noisy or it
makes me think about its meaning, it's too complex and should be simplified.

------
greggman
The problem is everyone is conflating things.

PHP the language sucks ass.

PHP the environment (part of the server + html processor + no setup or
configuration for most users + page is the app + etc..) = WIN for many many
people.

Not a single other environment has ever duplicated that. Until someone does
they'll never displace PHP. It's ripe for the replacing but understand that
it's not just the language, it's the entire environment surrounding it.

~~~
frankus
I found myself thinking whether one could make an heir apparent to PHP that
removed the suckiest aspects and left the same basic "no configuration, just a
bunch of files" model in place (any inherent problems with that model
notwithstanding). Sort of how SVN fixed some of the most glaring issues with
CVS without forcing people to really change their habits.

But I think that the things PHP really has going for it (huge installed base
of the runtime, huge installed base of legacy apps, huge developer community)
aren't going to smoothly make the jump to a new language. And once you've
given up that sort of backward compatibility, why not fix a few other things
while you're at it?

Still, I think there might be potential for a PHP-like language that breaks
some backward compatibility but fixes a lot of basic things like unicode
support, modules loaded at startup or runtime rather than as a ./Configure
flag, syntactic quirks, etc. Something where you could spend a few minutes to
a few hours (max) refactoring a PHP script into PHQ (or whatever you want to
call it) script and gradually modernize your app.

~~~
Zarel
Most of the gripes with PHP seem to do with its syntax, error messages, and
inconsistent function naming.

It seems like it shouldn't be too difficult to write an automatic converter
from "PHP" to "Improved PHP", which might solve a lot of these issues.

~~~
conner_bw
Obligatory "If PHP Were British"?

<http://www.addedbytes.com/blog/if-php-were-british/>

------
brendn
The arguments in favor of PHP that I continue to hear run along the lines of
"everybody's using it" or "it's not that bad if you know what you're doing" or
"it's great because it's the Swiss Army knife of languages."

It's hard to argue with those sentiments. And I think the root of the argument
stems from the diverging convictions of two distinctly different camps of
hackers. There are grease monkeys who love tinkering and see value in a tried-
and-true tool that works everywhere. And then there are the craftsmen who
strive for elegant code and choose their tools carefully. (There's truth in
both of those aspirations. Let's not get carried away in value judgements
between the two camps.)

But hearing "PHP sucks but I like it" sounds like Stockholm Syndrome to me.
There are some great aspects to PHP that other web stacks and frameworks could
learn from. Yet there are some major flaws that actually get in the way of
productivity. I hope we can keep the discussion constructive and learn from
both camps in building the future of web programming.

~~~
jack-r-abbit
I don't think you necessarily meant it as such but in this context it appears
that you just referred to PHP developers as "grease monkeys" and other
developers as "craftsman". One could misinterpret that as a highly offensive
remark.

~~~
brendn
I think you're misinterpreting my use of "grease monkeys" in general as
offensive. (I said not to project value judgements in my original comment.
There are certainly developers who see "craftsmen" as aloof purists who look
down on practical matters. It cuts both ways.)

~~~
jack-r-abbit
Well... The Google tells me that "grease monkey" is a derogatory term for a
mechanic. I don't think it is generally meant to describe someone that you
think very highly of. The Google also tells me that "craftsman" is a person
who is skilled in a particular craft or art. I think this is generally used as
defined. The Google never lies.

Using the two together seems to imply we have "skilled people who care about
elegant code and tool selection" and "mechanics that like to tinker". Like I
said, I don't think that is how you meant it... but that is how it comes off
to me. And I tried really hard not to project any value judgement.

~~~
tesseractive
The point of the analogy is to suppose that the primary goal of the PHP
developer, as with a supposed typical repair mechanic, is to dive into the
work and do what needs to be done to get to having a working site (or whatever
project). I believe this is similar to the sentiment expressed by the adage
"Real developers ship."

The "craftsman" approach in the analogy is presumed to be more deliberate in
his work, placing more emphasis on ensuring that the highest quality work is
assured, and comparatively less on the practical matter of ensuring that it
delivers what is needed on a short turnaround. One aspect of this analogy that
may be relevant to consider is that craftsmen are considered to produce high-
quality furniture and other products, but those products are quite expensive
compared to the products made in factories that most people (can afford to)
buy.

In professional development, software developers are generally expected to
balance these concerns. Produce the highest-quality product that it is
practical to deliver within a reasonable time frame.

No doubt this analogy is still an oversimplification of what PHP developers
(and other developers) are like, as virtually all analogies tend to be. But it
isn't intended to be derogatory toward PHP developers -- or toward developers
in general whose focus is on shipping a product and not producing the perfect
architecture.

~~~
jack-r-abbit
I guess in order to buy into the analogy you first must accept the premise
that being a craftsman and using PHP are mutually exclusive. I do not accept
this premise. But maybe we can just agree to disagree on that.

~~~
tesseractive
That's part of what I meant by calling it an oversimplification: _all_ of
_any_ developer pool are not going to fit some description.

Does the analogy apply to enough of the PHP developer pool to have value? My
guess would be yes, but if your experience dictates otherwise, I have no
problem with that assertion.

------
rpeden
Every time one of these arguments pops up, I'm reminded of this:

<http://i.imgur.com/pG3q7.jpg>

Different people will end up enjoying different tools. I started web
development with Ruby and Rails, but find that I really enjoy PHP. Then again,
I don't have to maintain anyone else's crappy code. I find that when I write
clean, well tested PHP, it really isn't frustrating or painful.

If you prefer something else, that's great! Use it. I guess these types of
debates aren't exactly unique to this industry though. When I used to lurk
around automotive message boards when I was younger, I recall some pretty epic
flamewars among Chevy/Dodge/Ford/etc. fans. Everyone loved their favourite,
and were certain that the others were clunky pieces of crap. Sounds a lot like
programming language flamewars... :)

~~~
bitwize
I really love that they used that famous photo of Andrew "Alynna \"Pookie\"
Trypnotk" Beaudoin for the C as seen by PHP fanboys cell of the table.

Oddly enough, that man's programming preferences are even more hilarious: he
likes to do his web development in the scripting language for his favorite
furry MUCK. I'm not even kidding; he bolted it onto a Web server somehow and
actually did paid contract work in this language. And since he was the only
one who knew how to use it, it meant job security. Up to a point. After he got
fired, he was also the only one who knew about the back door he snuck into
their MUCK-based application server.

Mofo was Dennis Nedry in a dirty fox fursuit. Or not, as the picture shows.

------
nthitz
Can we all just agree PHP (like many other languages) has some bad features /
design choices (evolutionary features, whatever you wanna call em), yet when
used properly under the right circumstances it does the job quite well?

~~~
mikeash
I'll accept "does the job". I don't accept "quite well". I've seen PHP do a
lot, but I've yet to see it do anything truly well.

~~~
methodin
What does it not do well?

~~~
mikeash
Since I haven't seen PHP do anything well, I'd posit that what PHP does not do
well is everything.

------
jrockway
The resounding theme is: "I've only used PHP, and I like it. Therefore it's
good."

Try getting good at a different programming language, then write your blog
post about how PHP is awesome.

~~~
soupboy
I don't buy your argument. You don't need to try all (or any) programming
languages in the world in order to like a single language. I know Python, and
I really like Python and think it is awesome. I don't need to have tried Ruby
or Haskell or C# to say this.

Also, your comment kind of becomes moot because he goes on to say "I do know
and actively use Python and server-side JS ..."

~~~
kelnos
_You don't need to try all (or any) programming languages in the world in
order to like a single language._

No, but you appear woefully unqualified to put forth any kind of opinion as to
why the language you like is a good language if you have no frame of
reference.

 _I know Python, and I really like Python and think it is awesome._

Sure, but you have no basis to make a comparison. You just happened to luck
out; Python _is_ a great language. PHP is... not.

~~~
giulianob
Languages I feel comfortable in:

-C#

-Java

-PHP

-ActionScript 3

-Javascript

-C/C++ (not so much now but did in the past)

-Objective C

and I've played around with Ruby and Python a little.

Knowing all these languages, I still think PHP can be damn good when used
properly. If you look at some of the frameworks built with it, they are clean
and powerful.

~~~
kelnos
That's the rub, though, isn't it? "When used properly". PHP doesn't at all
encourage you to use it properly. It doesn't define what "properly" is. The
original article detailing PHP's fractally-bad design gave an impressive list
of PHP's design flaws and all of the broken things it can do to you. If you
know these things and know how to avoid them, you're golden. But who
(especially new programmers) can be expected to know all those things?

I also think C++ is a pretty bad language, but you can do some very impressive
and clean -- and most importantly, maintainable -- things with it if you use
it properly. Unfortunately there are lots of definitions that people have come
up with that detail the "proper" subsets of C++ that are safe to use, with
disagreement on a bunch of things. (And for the love of $DEITY, please don't
lump C++ in with C, which is really a beautiful, amazing language.)

------
natesm
I don't like the "tools" analogy that always comes up. For example, Robertson
screws are better than Phillips head screws, which in turn are better than
flatheads. All of them are tools, and they all effectively do the same thing.
But the Robertson screw is better.

~~~
jack-r-abbit
And yet I have 5-6 different sized Phillips and standard screw drivers. I've
never even heard of Robertson screws.

~~~
stan_rogers
They tend to be known outside of Canada as "square drive" screws. They can't
cam out, are nearly impossible to strip in normal use, and will stay on the
driver tip without assistance in almost any attitude other than straight down.
They're the darling of woodworkers even in the United States of Phillips.

The American bias towards towards the Phillips screwdriver has mostly to do
with the gift of patent made to the government in order to support the war
effort, putting them effectively into the public domain. They were better than
flat screws/drivers, but that's not saying much: when I worked in aircraft
maintenance, about half of all of the Phillips-head captive fasteners (Camlock
or Dzus type) on inspection and access panels needed to be replaced _between_
periodic (400-hour) major inspections due to stripped heads.

~~~
jack-r-abbit
I've never encountered those but now I know why I have several square tips in
my drill's driver bit set. Thanks

------
robomartin
Had we waited for the development of ideal programming tools for the web, the
Internet would still be struggling to get off the ground. By making the best
of what we have and by continually evolving better solutions we've been able
to create something that has, quite literally, changed the world.

Let's keep that in mind. The goal and the end-result isn't a monument to
superb software engineering. What we create are experiences for, mostly, non-
tech users. How the sausage is made almost isn't important (as long as it
doesn't kill you). It's easy to get lost in the pursuit for technical
excellence and ignore the realities of building a business.

The fact that Facebook is built on PHP should pretty much tell the story and
put a lid on these endless arguments: You use whatever tools you have
available at the time to create a good user experience. People don't pay for
your choice of programming language. In fact, they couldn't care less.

That's not to say that the tech world should not strive to be on a path of
continual improvement and technical evolution. Not at all. I guess what I am
trying to say at one level is "quit griping and get back to building a
product, nothing else matters".

That said: What might be a likely improved successor to PHP? By this I mean, a
language that can gain wide adoption while dealing with a number of the issues
of PHP (and other languages) and has a high likelihood of being deployed as
far and wide as PHP is today.

~~~
blindhippo
If all the bitchy python/ruby purists out there want to build a successor to
PHP, here is the roadmap: 1) make it as simple to setup a development
environment as it is to install MAMP (this is somewhat done - but still hella
confusing with both Ruby and Python) 2) start a web host that can offer
rails/python hosting as simple AND as CHEAP as shared hosting (6$ per month or
less) 3) build the Wordpress/Drupal of Rails/Django 4) make it simple for
designers and "site builders" to hack the language. This includes former flash
addicts.

Until then, all this anti-PHP hate just seems... pointless. As you said, we
create experiences for users who ultimately don't care what is beneath the
hood as long as it works and doesn't blow up.

There are a lot of PHP systems out there and there is a lot of money to be
made as a developer who focuses on PHP. It may not be the prettiest language,
but I know why I focus on it - it makes me money. I use other tech (rails,
ObjC), but PHP is my bread and butter - and if you do it right, PHP really
isn't that bad.

The only time I've seen PHP apps blow up is when they are past due for re-
development anyways - a symptom that is not unique to PHP. Anyone who's seen
Rails spaghetti knows what I mean.

~~~
briandear
Rails hosting: git push heroku master.

Pretty damned simple. And cheap, for the level of hosting you get for $6 per
month, Heroku is free.

As far as Rails spaghetti, if you're using TDD, then it's easy to fix things
if new code breaks old code.

------
Kilimanjaro
I code like this in php, python, ruby, node and golang:

    
    
        include 'app';
        include 'models';
        include 'templates';
    
        $data = models::getCustomers()
        $view = templates::parse('customers',$data)
        app::show($view)
    

What's so ugly about that? I bet you I can build 90% of sites on the web with
that basic snippet of code. In any language...

~~~
vectorpush
Agreed. My web applications maintain nearly identical structures (with slight
variations due to some OO quirks across platforms) regardless of language
choice. At the end of the day most imperative scripting languages are
semantically equivalent.

------
monkeyfacebag
"WSGI in Python gets you part of the way there, but you still need to import a
library to talk to the server. This makes PHP just plain easier to get off the
ground for web applications."

The first sentence is mostly accurate, but I disagree strongly with the
assertion in the second sentence. Grouping related functionality into
libraries reduces the cognitive load of programming. The same could be said
for his assertion about the benefits of HTTP as a "first-class citizen."

I do agree that getting a PHP application running on a LAMP stack is easier
than say getting a WSGI implementation up and running, but this has nothing to
do with libraries.

~~~
ircmaxell
My intention was the full process from creating the first file, to getting a
server to serve the content is far easier to do in PHP than Python (granted,
in Python it's pretty much boilerplate, but there's a lot more than needs to
happen).

As far as the benefit of first-class vs libraries for handling the request,
that's something to consider (as there are arguments on both sides)...

~~~
drivebyacct2
That was pretty thoroughly discussed in the original thread. Yes, PHP throws
everything you can do into functions in global scope. It's "convenient" but
it's messy. It's also, correct me, but an incredibly trivial distinction.

------
grandalf
I've found that the people I know (even excellent programmers) who love PHP
tend to hate Ruby and find it extremely confusing.

Maybe there is just a fundamental brain-structure difference between
individuals... I don't actually think PHP is easier for a beginner than
something like Sinatra, so I don't buy the explanation that PHP is easier for
those new to programming.

~~~
flyosity
I think there may be something to this. I'm used to programming in PHP and
Objective-C and going to Ruby just throws my brain for a loop. I just can't
grok it, and reading someone else's Ruby code confuses the hell out of me. I'm
more of a designer than a programmer, so take this all with a grain of salt,
but coming from a C-style language background I totally feel like a different
part of my brain needs to turn on (or off?) to program in Ruby.

~~~
286c8cb04bda
This is a warning for future you:

Objective-C, when used like Objective-C and not just C-with-classes, is a lot
like Ruby. Both have a shared heritage in Smalltalk.

E.g. <http://www.cocoadev.com/index.pl?HigherOrderMessaging>

------
joe_the_user
It is very interesting how, often when one haphazardly produces a language for
a particular purpose, one winds with a language which both "sucks" and is
orders of magnitude better for that particular purpose than any other
language. Arguable examples include Php, Matlab, shell-script and many others.

I'm creating an ad-hoc language right that also has this quality. I cringe as
I shoe-horn one or another crude extensions into it and then step back and
realize that for its particular purpose, it would be harder to do that much
better.

------
1SaltwaterC
The biggest WTF was that "tied to Apache" section. Being running nginx + PHP-
FPM for years, even before FPM was accepted as official SAPI.

I guess that people still think that they know better than their sysadmin
regarding how to set up a production environment (regarding to the php.ini
rant). Maybe because the sysadmins know that expose_php = off turns off those
pesky easter eggs. Or they are better at Reading The F[...]riendly Manual
(<http://www.php.net/manual/en/ini.core.php#ini.expose-php>).

Had a good laugh at the complaints about PECL libraries that provide
"everything but the kitchen sink". Last time I checked, it was still "The PHP
Extension _Community_ Library". People should complain about that particular
project, if they need to. It has nothing to do with the internals team.

Wondering how he could forget about the <script language="php"></script> bit.

------
trebor
I'm with you Anthony.

I work all day with PHP even though I love Ruby (and Rails, and Sinatra...)
because practically ALL our client base wants either a static site or
Wordpress, or another PHP-based CMS. Few of our clients have the budget for a
custom web app with its own custom web stack to power it.

There's almost nothing faster to get bootstrapped into a functional
application or script than PHP. Assuming your server is already configured
with PHP you just upload the project.

PHP 5.3 and 5.4 give me great hope for the future of the language.

~~~
mattbriggs
"rails new project-name", and I have a full app. and heroku makes deployment
just a push away.

Its not like phps ease of use is not a good thing -- it is. but other
languages/platforms aren't _that_ much harder

------
antirez
I think many like PHP because an inconsistent language full of design flaws is
in many contexts better (in a less is more sense) than a good language that is
backed by a complex web framework and library system that contains too many
complexities, versioning issues, is slow by default or hard to tune, and so
forth.

With PHP people have something that just works, reasonably, and given that an
interpreter lives the lifespan of a "page view" making big errors is non
trivial.

So PHP is not a good language, but many other languages should learn something
from PHP. The problem is that the community backing this better dynamic
languages, such as Python and Ruby, still for some (IMHO obscure) reason
aren't shipping something that is PHP-alike, but just with a better _base_
language (without trying to add tons of abstraction layers).

I no longer use PHP because after years of using better languages (I like Ruby
as a "practical language") it's too hard to return back to PHP, but I often
find myself fighting with the useless complexities and layers of abstractions
that Ruby contains "by default". Not in the language or the implementation
itself, that is good enough IHMO, but in the tons of gems around and in the
integration with the web "side".

------
evilvoidhamster
I have written, maintained and worked on gigantic PHP codebases, mainly in the
realm of ecommerce (not that train wreck, magento). I have a lovehate
relationship with the language, and my pet peeve is that it is so easy, we get
the lowest ability developers who never take time to learn the theory or any
other technologies. Having said that... If it wasn't for the LAMP
infrastructure, the ease and speed of development, these codebases could not
have been developed.

I think the standard libraries could do with an update, to add the consistency
they deserve, and do update them to use modern features. The community for PHP
is reaching a point of maturity that it has not seen before (look at composer,
PSR-0, symfony2 and ZF2). I think this maturity is making the community a good
place right now. I'm not leaving it anytime soon.

Take away PHP, watch the major sites of the Internet disappear. Where would we
be with no Wikipedia?

------
freshhawk
> No Debugger - PHP has xdebug which works quite > well as an interactive
> debugger

Good god, what debuggers have you been using that makes PHP and xdebug seem
like it "works quite well".

------
10098
If I have learned anything during my 3-4 years of experience as a software dev
it is that

a) All languages, frameworks and technologies are bad and ugly, each in many
of their own horrible ways

b) Nobody has any fracking idea what they're doing (mostly)

c) Your best bet is to find something that does not hurt you as bad as other
stuff and stick with it. If you enjoy php, that fine (of course it's
completely beyond me how it is possible to _enjoy_ it, but its not the point).

On a side note, after having spent most of my time programming in high-level
languages, I wonder how things are down there in bare-metal-programming land.
I've grown tired of web development and I wonder what it's like programming in
an environment that does not have poorly designed, inconsistent frameworks and
leaky abstractions, only registers, memory and pins :) Too bad it's probably
too late for me to get started there.

~~~
cageface
I strongly disagree with A-C but I would encourage you to try some native
development if you're curious. HTML5 is the PHP of UI stacks and it's
tremendously refreshing to work instead in a well-designed stack like Cocoa
Touch or even Android.

~~~
10098
Actually I have done a fair amount of native development and I mean C++ stuff,
not mobile apps (android/iphone development is actually high-level compared to
that). I was really talking about going down even deeper than that, to the
level where there is nothing between your code and the machine. I try to
educate myself on the subject by reading books and occasionally coding
something in my spare time, but it's obvious that my current skill-set does
not even remotely comply with the requirements for that type of job.

------
ranza
I would still have to say that PHP, by all its flaws, gets the job done. And
in the end of the day thats what count to me. That might be a bad view to have
but I've been sticking with it for a lot of years now even though Ive flirted
with a lot of other languages. Its still the girl i get home to every night

------
datasage
Maybe its just me, but there seems to be a bit of confusion between frameworks
and language. Or many its that some languages are now rarely seen out of the
frameworks that made them prominent.

Because PHP was built for a web environment and has features that make it
quite useful out of the box, for that environment.

With Ruby or Phython you need to do extra work or jump into a framework to get
to that "starting point". However, if you are going to start comparing
Ruby/Python with a framework to PHP, then you need to look at PHP through one
of the prominent frameworks out today (Symphony, ZF, Etc). Otherwise you are
comparing apples to oranges.

------
FuzzyDunlop
> "You don't need a library or a framework to talk HTTP."

With 'library' typically meaning 'extension' in PHP parlance, you do. The
socket methods are part of the Socket extension, cURL is an extension you have
to compile in.

The only reason you'd not actually notice this is because, unless you compiled
your own copy of PHP, it will have been done in the default install bundled
with the OS, or in xAMP, and will have automatically been injected into the
'global' scope.

This is all just daft, though. You could go on forever with the "it can't do X
but it _can_ do Y" schtick, with any language.

~~~
wvenable
I think what he meant wasn't about sockets or Curl, but the fact that PHP is
integrated with the HTTP request itself. You don't need an extension for PHP
to output HTML or read in query parameters.

Python developers user REPL to quickly test elements of their code or play
around with the language; PHP developers hit refresh.

------
wazoox
This debate is always the same rehash of ye olde time story as recounted in
"The rise of Worse is better"[1].

That's why we had Unix boxes instead of LISP machines, that's why we had PCs
running MS-DOS and not Amigas, why we later had PCs running NT instead of SGI
Octanes, and nowadays people have PCs running windows7 rather than elegant
iMacs.

"Cheap and easy, quick and dirty, and get the job done" is a perfect
description of PHP and the very reason for its success.

[1]: <http://www.jwz.org/doc/worse-is-better.html>

------
conner_bw
Hating on PHP because it has too many functions is like hating on Chinese
because, instead of 26 letters that you can combine to write anything,
functional literacy requires a knowledge of between three and four thousand
characters and that's just sloppy language design!

Also, why not just call them an API to procedures written in C and realize
that none of us scripters are coding in anything.

I code in Lua.

------
bphogan
PHP is one of the languages I believe every web developer needs to know
reasonably well. It's not my go-to language though and I don't much care for
it. Let me explain.

My feelings on PHP are much the same as my feelings towards JavaScript - most
of the code I've encountered in the wild was cobbled together by designers who
knew nothing about programming and a lot about how to cut and paste scripts
together. I find myself blaming the languages for the mess people left me.

But occasionally, much like JavaScript, I'll encounter some PHP code that was
truly written by a master - someone who really knows how to use the language
effectively, who doesn't intermix SQL, HTML, PHP, and JavaScript in the same
1000 line index.php page. Well-constructed code, designed with purpose.

I suppose that's the same with any language, isn't it?

PHP, like JavaScript, is everywhere, and if you solve other people's problems
for a living, I think you need to know it reasonably well. At least well
enough not to make it worse than the last developer.

~~~
davidjbeveridge
Amen. I started my development career with PHP, and the cacophony of
intermingled responsibilities and languages in most PHP scripts is deafening.
It wasn't until I learned how to apply good OO design to PHP that I enjoyed
using it. That being said, I still don't work with PHP unless I have to. I
still don't like its mixed naming scheme for string/array functions or its
clunky hash/array syntax. At least the object support is reasonable.

------
andrewflnr
It shouldn't be that hard to configure some other language to fill the
ridiculously-easy-to-use niche that PHP fills. I vote for Lua, personally,
though almost anything would do.

Embed in HTML, wire stdout to the web page. Add a couple functions for "first
class HTTP support". Write an Apache module. You could probably make it even
easier to deploy than PHP, with the benefit of a nicer language. Obviously I'm
oversimplifying, but it's mainly glue code. Seems like the hardest part is
getting it deployed on the $5/month hosts.

Is there some obvious reason it hasn't been done? Did they already and nobody
cared? If I didn't already have a massive project backlog I might take a shot
at it. It seems like a good opportunity for someone to make a difference.

Edit: Crud, they already took the name mod_lua:
<http://httpd.apache.org/docs/2.3/mod/mod_lua.html>

------
seldo
I loved the original post about PHP's fractal awfulness, but this sums up my
feelings about it: I like it anyway. His point about PHP being shared-nothing
by default is a good one: this is indeed a big part of the admirable
scalability of web apps written in PHP (Facebook, anyone?).

The one point I'd disagree with is his assertion that PHP doesn't have a
templating language. Of course it doesn't: PHP _is_ a templating language.
That's what it was written to be. Many of the uglier things you have to do in
PHP are related to the fact that what the language always _wants_ to do, by
default, is spit out a web page.

If what you want to do with your software is output web pages, then PHP is the
best call. If you want to do basically _anything_ else, pick another language.
But at web applications, PHP just can't be beat.

~~~
wpietri
I'm glad you like it, but the "shared-nothing" line is outrageous bunk.
Commonly repeated bunk, so I don't blame you, but it's still bunk.

Pretty much every PHP app in the world shares a database. So you've shifted
your scaling problems from an area that programmers understand and control to
a 1-MLOC mystery.

I bring this up because I have a few friends who make their living saving the
asses of PHP programmers who buy the notion that PHP is magically easy to
scale. I hear a lot of horror stories from them about the absurd sums of money
spent cleaning up the messes.

I do agree that PHP is fine for doing basic web apps. But I don't know anybody
doing anything serious with PHP that only uses PHP, because serious web apps
eventually need more than you can do in that language. PHP's "shared-nothing"
scaling just means that when the going gets tough, some language other than
PHP will be doing the work.

~~~
seldo
You're right that the back-end often gets ported to some other language when a
PHP app is scaled-up; this goes with my point that when you move away from
spitting out web pages, another language is a better choice.

I'm not sure your point about a database is valid; Python and Ruby and Perl
apps are all using a shared database (or newer k-v store) as well.

~~~
wpietri
My point is that it's the place where all shared state is kept. "Shared
nothing" is a lie because it's sweeping the sharing under the rug of the
database.

I agree that most web stuff written in scripting languages is built around a
database for shared state. But in more powerful languages, you have other
options.

------
kemo
Yes, PHP can suck in many ways. Yes, everything else seems to be more elegant.
And yes, newbies don't care. They just want it to work, no matter how. They
don't care about creating servers (node) or including something they know
nothing about (sinatra). Heck, they might do it with PHP as well, if they knew
how to (Kohana?). But they don't and they never will.

On the other side, put good developers on a PHP project and you will get a
good product, regardless of the haystack position and possibility to suppress
errors (etc. etc. etc.). The fact that there is so much spaghetti PHP out
there doesn't make it impossible to write good code with it. And that matters
_a lot_.

------
jwbrown77
I think the PHP documentation is the major thing not mentioned here for the
non-programmer layman (like me, who uses PHP).

Need to know how to use in_array?

<http://us.php.net/manual/en/function.in-array.php>

Not only is there a quick reference on the top, but clear, concise, and
diverse examples on how to use it if you don't want to spend time thinking
about how to work the arguments.

Maybe the expert programmer doesn't really care about these qualities, because
javadoc is "easy" to them, but it doesn't compare to this for me.

P.S. As someone who has dabbled with Ruby, Python, etc. I do acknowledge they
are vastly superior languages in many respects.

~~~
chromatic
If you're glad that PHP.net exists because you can always look up the order of
needle and haystack, you'll love a language where the order of needle and
haystack is always consistent.

------
danso
I used PHP awhile back, but how much of its inconsistencies can be resolved
without fundamentally changing the language's positive features? That is, not
caring about backward incompatibility. Like, I can't imagine the inconsistency
of "==" has any bearing on PHP's flexibility.

~~~
wvenable
If you don't care about backwards compatibility you leave a lot of users in
the lurch. PHP4 to PHP5 took years to migrate over and Python 3 still hasn't
taken over from Python 2. Perl 5 and 6.

If you can't get syntax/semantic changes adopted in a single language then
getting a whole new language adopted is a non-starter.

I think the core PHP developers should take a long look at the inconsistencies
of the language and formulate a plan to reduce/eliminate them without breaking
backwards compatibility. In some cases, it should be relatively easy but in
others it will be very difficult. The inconsistency of "==" would be hard to
fix while making sure old code still runs correctly.

------
calloc
I really dislike it when someone posts something controversial so a couple
hours later someone posts the opposite based on their experience.

This doesn't add anything useful, post it as a link on the original thread. It
is just a bunch of noise cluttering up the frontpage of HN!

------
vectorpush
A novice programmer can write dangerously horrible code in C or C++ but we
don't say those languages suck (most of the time). I'd rather debug/refactor a
poorly engineered PHP project than a poorly engineered C or C++ application
any day of the week.

~~~
Scriptor
C or C++ aren't competing with PHP. You'd have to look at Python or Ruby in
this case. While it's definitely possible to write shitty code in those
languages it doesn't provide nearly as many ways to screw up. Besides the lack
of language features like @ (error silencing), you won't find nearly as many
terrible tutorials out there created by some guy who's been learning for a few
weeks and decided to write a blog post.

Given a poorly engineered PHP or Python project, I will always pick the
latter. However, if I were to start a project on my own I'm confident enough
in my PHP that the language choice is harder to make.

~~~
vectorpush
_C or C++ aren't competing with PHP._

That's true, but my point is that there isn't such a visceral hatred for C and
C++ even though they are widespread and notorious for memory leaks,
vulnerabilities, indecipherable corporate quagmires (perhaps due to an over-
engineered OO architecture or 700 line functions or opaque symbol names or
dependency hell, etc).

 _Besides the lack of language features like @ (error silencing)_

Red-flag bad practices exist on all platforms. The horror story of a PHP
project littered with error suppression is like opening up a C project and
discovering that the control flow is guided by a 200 label GOTO architecture.
It's not PHP's fault that the programmer abuses the language, it's the
employer's fault for hiring a highschool student at $15/hr.

~~~
nupark2
> _That's true, but my point is that there isn't such a visceral hatred for C
> and C++ even though they are widespread and notorious for memory leaks,
> vulnerabilities, indecipherable corporate quagmires (perhaps due to an over-
> engineered OO architecture or 700 line functions or opaque symbol names or
> dependency hell, etc)._

C is enormously more consistent, better defined and specified, and well-
documented than PHP.

It's a solid enough language with a very specific use case, and not even
remotely competing with PHP.

PHP is a terribly inconsistent, poorly defined, poorly documented, poorly
implemented, poorly designed language that can't do _anything_ better than
_any_ of the other languages it _is_ competing with.

The one thing PHP has going for it is inertia. That's _it_.

~~~
vectorpush
_C is enormously more consistent, better defined and specified, and well-
documented than PHP._

Yes, this is a trite and negligible truth of PHP. A developer suffering any
significant loss of productivity due to problems like mismatched
needle/haystack parameters just isn't very competent. It's a non-issue if the
developer is being paid a real salary. I'm not saying these issues aren't
important enough to warrant attention, but the debate between maintaining
backwards compatibility and squashing bad practices certainly isn't exclusive
to PHP.

 _and not even remotely competing with PHP._

I already addressed this in my previous post. I'm not suggesting that PHP is
in competition with C, that should be pretty obvious. I'm asserting that C,
like PHP, is ridden with dangerous pitfalls for developers who don't know what
they're doing. PHP is just easier to work with for a novice programmer.

 _The one thing PHP has going for it is inertia_

And did that inertia spontaneously emerge from a vacuum? In the spirit of
PHP's namesake you've devised a recursive argument to explain the only
conceivable upside to using PHP.

~~~
nupark2
> _Yes, this is a trite and negligible truth of PHP. A developer suffering any
> significant loss of productivity due to problems like mismatched
> needle/haystack parameters just isn't very competent. It's a non-issue if
> the developer is being paid a real salary. I'm not saying these issues
> aren't important enough to warrant attention, but the debate between
> maintaining backwards compatibility and squashing bad practices certainly
> isn't exclusive to PHP._

You're just hand-waving away the issue. "Yes, you have to keep far more in
your head at once to make sure you don't step on a PHP landmine, but that's
why we're paid the big bucks!"

I'm sorry, but this is a false dichotomy and an inaccurate parallel with C.
C's landmines are well-defined, understood, and derive from the target purpose
(portable assembly). PHP's landmines are ambiguous, ill-defined, and just
plain stupid, often caused by what amounts to a truly brain-dead lack of
cognitive effort on behalf of the language authors. The language is poorly
specified such that even if a developer should wish to invest sufficient
effort, it's impossible to know where they all are.

Moreover, there are such ugly corner cases built into the language and common
libraries that some landmines are entirely unavoidable. Whose brilliant plan
was it to make fopen() accept URL parameters instead of defining a common
stream API that arbitrary stream types could support?

Let's say I want to treat a byte array as a stream -- this is a pretty common
thing to do in most languages:

    
    
      fopen('data:text/plain;base64,'.base64_encode($data), 'rb');
    

Are you bloody kidding me? That's just the smallest, tiniest tip of the PHP
iceberg of stupid-in-action.

> _And did that inertia spontaneously emerge from a vacuum? In the spirit of
> PHP's namesake you've devised a recursive argument to explain the only
> conceivable upside to using PHP._

PHP's inertia emerged out of ill-qualified individuals adopting the language
as the most visible available option during a time when there was largely a
dearth of options and limited understanding of the web as a platform and "what
comes next" from CGI.

People -- collectively, as a group -- adopt poor solutions to their problems,
simply as a matter of compounding gravitation and a lack of understanding of
the long-term implications.

It's simple group decision making, and it's not reasoned, nor is it
necessarily likely to produce the best possible answer, or even a good one --
_especially_ when the group in question is ill-equipped to understand the
problem space they're working in.

------
Killswitch
Well said. PHP gets a lot of crap thrown at it, but in the end, one of the
biggest companies and second biggest website on the internet uses it as it's
primary language.. If it's good enough for them, it's good enough for any of
us to use.

~~~
10098
Facebook pretty much _has_ to use php, they can't afford to rewrite all of
this huge codebase. They have written their own compiler that translates php
to c++ and then uses g++ to compile that into native code. I'm sure they had
some pretty serious reasons to do that. And they probably wouldn't have to do
that sort of thing if facebook wasn't written in php in the first place. Thus,
the argument "hey, facebook is written in php so let's use php" is invalid,
it's a typical "cum hoc ergo propter hoc" fallacy.

~~~
Killswitch
That's the backend. The front end stuff that average Facebook users interact
with is raw PHP.

~~~
10098
How do you know that?

------
TazeTSchnitzel
PHP sucks, but it will get better over time. Maybe they'll try to do a big
leap like Python 2 to Python 3, which would be great.

I'm not a big fan, but I like the fact the developers seem to be trying to
improve it.

------
aaronsung
I love PHP too, I can't agree more for the 'just work' point, besides unicode
isn't built in. (It 's really a pain for far east users like me)

------
zippie
The OP says PHP doesn't have XSS filtering but that is simply not true:

<http://www.php.net/filter>

------
rometest
wait. after reading the earlier article, i started learning python. you guys
cant do this.

i need to go back to php now or wait till the wwIII is over

~~~
Gigablah
Why not learn both?

~~~
PerG
Good point there, Gigablah

------
mickgardner
"PHP Sucks" [....] Yep, agree with that part....

------
ygmelnikova
Can't we all just get along?

------
anonymousab
It's often called "c++ on the internet" but C++ was never a pretty language.
At the very least, it is better than ASP. Good lord, ASP is such a hunk of
garbage.

~~~
TomGullen
ASP.net or Classic? Remember Classic was first released 14 years ago, a lot of
great stuff has been built in it. I'm not sure why you would call either a
hunk of garbage!

