
Stack Overflow: Defend PHP - convince me it isn't horrible - Chirag
http://stackoverflow.com/questions/309300/defend-php-convince-me-it-isnt-horrible
======
weego
These topics always just smell of "Now I'm a grown up programmer I'm going to
tell the world how much I understand by slamming an easy target language".

I love PHP and have used it for years since moving away from asp.net and agree
with some of the posters arguments as a theoretical principle, but as day-to-
day PHP developer I also say so what. Naming and parameter inconsistencies?
Yes, my libraries have that too and I can at least learn the PHP ones with
some experiernce. I don't know any asp.net developer that doesn't have to use
some kind of tool to help them find where
System.Obscure.FoundItOnline.Function exists in the monster .net namespace
system. It allows me to be productive and allows me to be the gatekeeper of
how well or poorly I implement things. This is a crucial point of the constant
argument about poor PHP logic/presentation support for me, I can happily write
mixed and messy code for a £500 job or I can write some clever system that
implements caching and output buffer manipulation and have a great template
system.

There are far too many people spending far too much time thinking that
academic level programming considerations are applicable in every detail to
every day programming practices of web developers.

~~~
lhorie
Agreed. Fwiw, many of the complaints apply to other "better" languages also:

\- _PHP has inconsistent naming of built-in and library functions._ \- C has
types like int, size_t, jmp_buf and FILE

\- _PHP performance is abysmal without caching_ \- MRI Ruby is pretty slow too

\- _Functions are case insensitive_ \- Lisp anyone?

etc etc

The whole meme of PHP warts seems more like an exercise in confirmation bias
than objective analysis.

~~~
marte
Yeah, but if we continue that logic and fill up that "etc etc" it would seem
that the other languages have their own bad features and PHP combines them
all.

~~~
lhorie
That "all" is what I'm referring to when I mentioned confirmation bias. PHP
programs don't segfault when you have a typo. You don't have macro expansion
problems. It's not particularly verbose. Most languages have a ton of issues.
Imho, the stuff in the PHP list is pretty minor compared to some of the warts
in some other languages.

------
pilif
I'm spending most of my time maintaining a web application consisting of
around 150k lines of PHP code. We (well - initially, it was just me) began
development back in 2004 but since then the application has grown constantly.

Back in 04, I already felt some reservations against PHP, but that's what I
knew best and that's what was most used for the web (Rails might have been
around, but not really known - other ruby options were not quite there yet.
Python I disliked and Java I. don't. touch.).

The application was written in PHP5, initially developed on some RC of 5.0.0
and I was careful to keep a clean style and not using deprecated code.

This lead to a quite clean application that I could really be proud of. And
still: While it has suffered from sometimes not quite reasonable customer
demands, it's still very good at what it's doing and while there might be some
dead bodies rotting in the code, it's nowhere near daily WTF material (aside
of some bugs we have a good laugh at and fix shamefully).

Still. I have some bad gripes with PHP that made me stop doing anything new in
that language.

I can easily live with the usually quoted problems though:

\- parameter order in library function? I don't care - my IDE lists them.

\- Huge base library? I don't care as the stuff I don't need doesn't cost me
anything but disk space and the stuff I do need, I'm glad is there.

\- No namespaces? Yeah. Bit me a couple of times, but I can work around that -
besides, with 5.3 we got namespaces, so this doesn't count any more

\- Performance issues? It's fast enough for said application.

\- Security? It's just as secure as any other language you can write insecure
code in (i.e. all of them).

\- Allows intermixing of layout and code? Sure, but you don't have to. If you
have _any_ sense what so ever, all requests go through a central /index.php
and all other code is in some not-publicly accessible location and emits no
html what so ever. All output is generated using any of the thousands of
templating libraries.

What really disturbs me about PHP is its type conversion rules. 1 == '1' or
even worse 'foobar' == 0, or '123n' == 123. This is cause for so many subtle
bugs.

Just use === you tell me? Sure, but then you clutter your code with an insane
amount of isset()'s and isint()'s and whatnot - the fact that the database
library I'm using (pgsql) returns everything as strings doesn't help that
cause either.

The other thing is the really clumsy syntax. Array literals, anonymous
functions, closures (with explicit declaration of all variables of the outer
scope you want access to), operators, even just the lack of named function
parameters. The syntax is clumsy and all the elegant code you see even from
JavaScript just gets bloated and unreadable once you port it to PHP.

These two issues made me do stuff in Ruby, Python(3) and lately a lot of
Node.js, but the maintenance of that huge application remains to be the main
part of my day-job and even though the two issues really bug me, it's still
not painful enough to really be complaining (or, heaven forbid, port the thing
to whatever-other-language-thats-currently-hip).

So in retrospect, while I'm as die-hard a PHP user as you can get with many,
many lines of PHP under my belt and while I do find some of the stuff highly
enjoyable (php's arrays that are also ordered hashes for example. Or the
really easy and accessible web-server/HTTP integration), I also dislike it
quite a bit to the point of being unwilling to start something new in PHP.

~~~
mfukar
_It's just as secure as any other language you can write insecure code in
(i.e. all of them)._

That may be true; I've only developed two half-serious projects in PHP a while
back. But given the amount of XSS and injection vulnerabilities we're seeing
daily, I think that something is wrong with those web development guys. PHP is
admittedly a widely used tool and I can't help but wonder: " _Could it be just
the language? Is there a possibility things would be better if PHP was
abandoned?_ ". Of course things would improve if we educated all PHP
developers on the security implications of whatever it is they're programming.
But so many years of coding have shown it's infeasible (for any language).

~~~
generalk
_Is there a possibility things would be better if PHP was abandoned?_

Nope. Beginning coders write vulnerabilities until they're otherwise educated.
In PHP these are SQL injection and XSS holes. In C they're buffer overflows.

 _Of course things would improve if we educated all PHP developers on the
security implications of whatever it is they're programming. But so many years
of coding have shown it's infeasible (for any language)._

Education is feasible for any language. Some segment of the programming
population will always remain uneducated -- laziness or apathy on their part
-- but this doesn't mean education doesn't work.

~~~
mfukar
You mean to tell me that in a world where anyone could take up on any
programming language and start writing code on one's own, properly educating
that someone is feasible?

Please. This isn't 1960 anymore. Code is not written by "scientists"
exclusively anymore.

------
terra_t
The real advantage of PHP is deploy-ability.

If you choose mod_perl, mod_python, JSP, or most of the classic environments
you need a sysadmin to take care of the web server... It's going to crash from
time to time, run out of memory, and otherwise make trouble for you.

PHP's mode of integration with the prefork Apache web server is almost
trouble-free... It's such a big difference that there could be a "blub" factor
here... People who program in other environments often have a really hard time
believing that a large fraction of the sysadmin activities that they are doing
just don't need to be done if you're running PHP. (You can go five years and
never "kick Tomcat", something that some shops have to do every 5 hours).

That said, scaling comes to play here. For a small company or for a company
that's doing a number of small projects, the cost of system administration
that comes with other programming environment matters a lot more than it does
for a big company. It's not such a big factor for a company like Facebook.

On the other hand, PHP forces people into a "shared nothing" model that scales
well and ~eliminates~ a wide range of concurrency-related problems that are
endemic to thread-based backend apps. For instance, quite often I've seen a
race condition in an ASP.NET app and had everybody on the team swear up and
down that there's no shared state, then I spend a few hours looking at the app
and there's a static variable that nobody knew was there.

Another strength of PHP is that it has a very complete library that's largely
correct. The PHP team is much more honest about what works and what doesn't
work than a lot of others (PHP and Python have the same problem with threads,
for the same reason -- PHP says "don't use them", Python says "jump in the
water is fine".) If you program in some weird-o language like Haskell you'll
probably have to write your own urldecode function and you'll probably be so
busy thinking about higher-order functions you won't pay attention to
details... Like making it work right. (Perl has a broken urldecode function in
CPAN FOREVER)

Don't get me wrong, there's plenty to hate about PHP; but try to get some real
work done in environment X and you'll find plenty to hate too.

------
brlewis
I'm not a PHP advocate, but I'll take this one:

 _PHP encourages (practically requires) a coupling of processing with
presentation. Yes, you can write PHP that doesn't do so, but it's actually
easier to write code in the incorrect (from a sound design perspective)
manner._

The ideal web application is the one that best fits the unique characteristics
of the data being manipulated. When exploring how a web app should work, you
_should_ be thinking at all levels: view, controller, model. A framework that
forces you to separate all three from the start is a bad framework. It pushes
you toward generic data manipulation forms and reports. If those generic tools
are the best ones for the data model being manipulated, why involve a
programmer at all?

We would have much more interesting and varied web applications out there if
the prevailing "wisdom" of MVC would die.

~~~
jemfinch
> When exploring how a web app should work, you should be thinking at all
> levels: view, controller, model.

And separating those aspects programmatically makes it _easier_ to think about
them, not to mention program the ideas that occur to you when thinking about
them separately.

> If those generic tools are the best ones for the data model being
> manipulated, why involve a programmer at all?

If intertwining essentially unrelated ideas is the best way to write programs,
why use high level languages at all?

MVC--just like garbage collection, just data abstraction, just like most other
high level languages features--is about modularity and separation of concerns.

> We would have much more interesting and varied web applications out there if
> the prevailing "wisdom" of MVC would die.

How do you reconcile this with the fact that there occurred a veritable
_explosion_ of various interesting web applications when MVC was
(re)discovered by the webdev crowd?

~~~
brlewis
The explosion you speak of is sites making better use of JavaScript, a
movement that took off with the launch of gmail in 2004. Paul Buchheit talks
about the thinking and communication that created gmail. He doesn't mention
MVC; he talks a lot about rapid prototyping. He shares some of his then-
current thinking in the form of a single 600-line source file. Read the post:
[http://paulbuchheit.blogspot.com/2009/01/communicating-
with-...](http://paulbuchheit.blogspot.com/2009/01/communicating-with-
code.html)

EDIT: HN discussion: <http://news.ycombinator.com/item?id=444615>

------
pierrefar
I think this is the wrong approach. The guy should try to convince me that PHP
is bad. That PHP has never not did what I wanted it to do. That I need to
invest time and switch to some other language because it's better for my needs
and purposes, and the switch will quickly get me to a level of expertise that
I have with PHP now.

The fact of the matter is PHP is ugly and that's really it. I can live with
ugly because I know it and it does everything I've ever asked it to.

Frankly, it's no different than me switching from English because it has
quirks.

~~~
mfukar
_The guy should try to convince me that PHP is bad._

It goes both ways: he has tried to do certain things with PHP and made his
life miserable; you've done certain things with PHP that made your life
easier.

Telling each other which is which will let the one know what to avoid and the
other one what's he doing wrong.

Anyway, it's about time we started thinking and being more mature than 'my
language is better than yours'. Which is why I hate all similar postings and
articles which aim to enlighten me On the Amazing Features Of Language X (or
the opposite).

------
byoung2
This debate reminds me a lot about another debate about language. When I
studied English in college, I occasionally came across papers enumerating the
weaknesses of the English language. It's terrible for writing poetry, because
you can't rhyme like you can with Italian or seduce like you can with French.
It's difficult to learn, because of irregularities in spelling and
pronunciation.

Now that I'm a PHP developer, the response I give when people ask me why I use
PHP and not a "real language" is the same one I would give if someone asked me
why I speak English. There are more people who speak my language. If I travel
to a remote fishing village in China, chances are I can find one person who
speaks English. Try to find someone who speaks Italian. When I'm working on a
web project, I know that if I write it in PHP I can find hundreds of
developers to hire at a reasonable price versus hunting around for Ruby
developers (who cost double).

At my day job, we run 200 websites, and 194 of them are written in PHP (1 is
Java, 2 are .NET, 1 Ruby, 2 Coldfusion). When the company buys sites, the
first step is converting them to PHP (if they aren't already), just so future
maintenance is easy and cheap.

------
DrJokepu
To be honest I don't think case insensitivity is really that much of an issue.
Common Lisp is case insensitive as well and I have never had any problems with
that.

~~~
DCoder
They could have made it fully case sensitive, or fully case insensitive... but
they went for the confusing middle point:

    
    
      foobar() == FOOBAR()

but

    
    
      $foobar != $fooBar
    

And then there was that fun issue with the Turkish locale and function
names...

------
Goladus
Actually, I think the depreciation point is one of the better points. Yeah,
sometimes clean up is necessary, but when a language is a moving target like
that, it raises serious concerns about portability and long term maintenance.

~~~
arnorhs
But the PHP guys had told us about the deprecation of pass-by-reference years
before it was deprecated. I think that's a really good argument _for_
portability and long term maintenance.

It they would've simply changed it over night, I'd have problems.

------
delano
No one ought to convince anyone of anything.

Use it yourself and keep using it for as long as you like it. When you stop
liking it, stop using it.

That doubles as a recipe for learning any new thing.

------
billpg
I wish I could ignore PHP, but it's just so darn ubiquitous. Most webhosts
priced within the means of "normal" people have PHP, while far superior (IMO)
platforms like ASP.NET are the exception. Until webhosts can be convinced to
support a wider range of platforms, I fear humanity will never be freed of the
bonds of PHP.

Bill, hates PHP with the heat of a thousand suns.

------
steverb
Personally, my distaste for PHP centers around the fact that there are so many
developers pumping out crappy PHP code for $20 / hr.

I don't need to compete in a race to the bottom.

------
Yaggo
From a programming language perspective, PHP is somewhat horrible (PHP 5.3
less so, but still). I guess nobody will deny that. But from practical
perspective, PHP is very suitable tool for many tasks and has huge ecosystem
behind it. Complex real-world websites and applications have been successfully
built with PHP. Isn't that proof enough?

Do you consider yourself a purist or pragmatic? In the latter case, PHP may be
worth dating for a while.

~~~
billpg
"Complex real-world websites and applications have been successfully built
with PHP."

Thanks to PHP or in spite of PHP?

~~~
Yaggo
:-)

Seriously, I like the photographing analogy: "Wow, what a photo you have
taken! You must have really good camera?"

A programming language is rarely the limiting factor. Skillful programmer may
benefit from advanced language, but mostly it's about knowing your tools and
the bigger concepts, regardless of the language. Try yourself and learn to
master something you like most. (My current choice being Python.)

------
slantyyz
It's a little pointless to defend PHP to someone who thinks it's horrible.

That's like asking someone to defend a religion. A waste of time and energy.

In a good programmer's hands, the results will be good, regardless of language
or platform choice.

Sure, you can argue the finer points until you're blue in the face, but in the
end, the only thing that should matter to your "customer" is that the solution
satisfies his/her needs.

------
jamesmontalvo3
I'm wondering, as a fairly inexperience programmer with most of my time in
PHP: is there any good reference for "How to start web development in ___ with
previous experience only in PHP". I would love a tutorial that explained how
to accomplish in another language all the things that PHP makes simple for
newbies. I'd also be totally willing to help an experience person develop such
a tutorial.

------
bufordtwain
"There are more useful systems developed in languages deemed awful than in
languages praised for being beautiful--many more." -Bjarne Stroustrup

------
hsarvell
PHP is great if you need to get some small thing up and running yesterday. PHP
is also great if an out of the box solution will almost fit the bill due to
the fact that there are so many. Just take a box and do some small
modifications, voila, done!

~~~
arnorhs
...or big thing running yesterday, right? Take Facebook for an example.

To me, Facebook seems like a pretty complicated piece of software. The concept
isn't very complicated but there are _so_ many features all over the place.

~~~
shod
He didn't say you _can't_ use PHP for such things, he said PHP is "great" for
getting smaller sites built quickly. It's possible to build very large apps
with PHP alone, if you like, but there are other solutions I think are
preferable. Most of them weren't even available when Facebook was born.

For example, I would rather build a Facebook-sized app in Rails than a PHP
framework, especially with Rails 3's new features. There are some very capable
PHP frameworks out there, but you'll still end up writing much larger models
and a lot more code than if you were using Rails.

~~~
wvenable
Rails would get you started on Facebook app quicker, but then you'd be forever
fighting the framework to do things outside of it's core abilities. For
something as large as Facebook, that will be all the time.

------
noodle
php is a tool. it has its benefits and its drawbacks. you shouldn't have to
"defend" the language itself, but you should be able to defend your choice of
language. if you don't like a language, go use another one.

------
snorkel
Facebook and Wikipedia.

------
hackermom
PHP may be one weird concoction, that's for sure, but all of the arguments
brought up by this guy - and this is the exact same boring song belched out
whenever there's an argument of "PHP is a terrible language" - fall into the
category of vanity, because no matter how one twists and turns these points
they still really don't make the language itself terrible, and they don't make
PHP one bit less capable, nor one bit less adequate for the supposed job.

~~~
Daishiman
What do you mean?? Do you have any idea of just how many programmer hours have
been wasted by the absence of features, just how insecure so many web apps are
due to the weird casting system and lack of safety-oriented features.

My impression is that people who claim PHP has not cost them development time
have simply never looked at alternatives that solve many of the problems.

~~~
hackermom
Without going off on a limb, I'm guessing you're a not too experienced
developer. You comment as if instead going for Perl, Ruby or ASP inherently
makes an application safe, saves buttloads of manhours etc. And you're wrong.
Gravely wrong.

Excluding the obvious issues caused by bugs that are a natural part of any
programming language's development, security problems are not caused by the
language chosen, but by the developers themselves.

~~~
chromatic
A well designed language or library can decrease the likelihood of specific
bugs, and especially security problems. Imagine the existence of a library
which made it easier to use SQL placeholders than to concatenate user input
into a string. Imagine PHP without register globals.

~~~
hackermom
PHP already does that via PDO. PHP's "Register globals" was deprecated exactly
one year ago, in 5.3.0.

~~~
moell
That was exactly chromatic's point---language design and features _do_ make a
difference.

~~~
hackermom
It's always easier to blame the tool for your failed craft than it is to be a
good programmer, isn't it :)

Putting PHP in the "inadequate corner" or trying to convince oneself that it
is lacking in features is just an easy excuse.

~~~
chromatic
_It's always easier to blame the tool for your failed craft than it is to be a
good programmer, isn't it :)_

Do you object to the attractive nuisance doctrine?

------
ndimopoulos
To answer to the topic of the post - why should I (or anyone else for that
matter) bother trying to convince the author that PHP isn't horrible.

If the author does not think that PHP is suited for his/her needs then he/she
should not use it. There is a plethora of programming languages out there -
pick and choose.

The post has a disconnect between the title and the content. The author does
not want to use PHP and tries to outline the flaws in the language from
his/her own view. Sorry to disappoint, but I disagree with those points. I use
PHP amongst other programming languages and I use it only when it suits my
needs and the needs of my project. It is not perfect but then again nothing
is.

Final thought for the article would be a paraphrase of its title as a reply:

Defend 'behaviour'. Convince me it isn't spelled horribly - correct spelling
'behavior'.

I think you get the point :)

~~~
raganwald
My friend Anthony Lewin and I were Macintosh salespeople back in the Dark
Times when Jedi Master Jobs was in exile. People would walk in to the store
and ask the same question:

    
    
        Convince me: Why should I buy a Mac instead of a PC?
    

Anthony quickly learned not to feed the trolls. He would say "I don't know.
Why _would_ you buy a Mac instead of a PC? Most people buy PCs. What's so
special about you that you need what a Mac has to offer?"

The genuinely curious would explain about their graphics needs or what-not,
and Anthony would go from there.

I think of Anthony when I see questions like this. My response back to the OP
is to ask _Why should you use PHP? What's so special about your situation that
you need it?_

~~~
hnal943
Doesn't this fit more appropriately the other way around?

"I don't know. Why would you use a language other than PHP? Most people use
PHP. What's so special about you that you need what another language has to
offer?"

In your example, the PC is the inferior but nearly ubiquitous (and easier)
choice. Isn't that the position PHP is in as well?

------
sandGorgon
Drupal, Joomla, Wordpress, phpbb, vbulletin, invision power board:: Together
they are 99% of online communities + personal websites. If you want to use any
of them. Then it is php.

I may not particularly like PHP, but to deliver projects in reasonable time,
you may have to leverage PHP

