I <3 Steve McConnell*
Coding Horror
programming and human factors
by Jeff Atwood

May 20, 2008

PHP Sucks, But It Doesn't Matter

Here's a list of every function beginning with the letter "A" in the PHP function index:

abs()
acos()
acosh()
addcslashes()
addslashes()
aggregate()
aggregate_info()
aggregate_methods()
aggregate_methods_by_list()
aggregate_methods_by_regexp()
aggregate_properties()
aggregate_properties_by_list()
aggregate_properties_by_regexp()
aggregation_info()
apache_child_terminate()
apache_get_modules()
apache_get_version()
apache_getenv()
apache_lookup_uri()
apache_note()
apache_request_headers()
apache_reset_timeout()
apache_response_headers()
apache_setenv()
apc_add()
apc_cache_info()
apc_clear_cache()
apc_compile_file()
apc_define_constants()
apc_delete()
apc_fetch()
apc_load_constants()
apc_sma_info()
apc_store()
apd_breakpoint()
apd_callstack()
apd_clunk()
apd_continue()
apd_croak()
apd_dump_function_table()
apd_dump_persistent_resources()
apd_dump_regular_resources()
apd_echo()
apd_get_active_symbols()
apd_set_pprof_trace()
apd_set_session()
apd_set_session_trace()
apd_set_socket_session_trace()
array()
array_change_key_case()
array_chunk()
array_combine()
array_count_values()
array_diff()
array_diff_assoc()
array_diff_key()
array_diff_uassoc()
array_diff_ukey()
array_fill()
array_fill_keys()
array_filter()
array_flip()
array_intersect()
array_intersect_assoc()
array_intersect_key()
array_intersect_uassoc()
array_intersect_ukey()
array_key_exists()
array_keys()
array_map()
array_merge()
array_merge_recursive()
array_multisort()
array_pad()
array_pop()
array_product()
array_push()
array_rand()
array_reduce()
array_reverse()
array_search()
array_shift()
array_slice()
array_splice()
array_sum()
array_udiff()
array_udiff_assoc()
array_udiff_uassoc()
array_uintersect()
array_uintersect_assoc()
array_uintersect_uassoc()
array_unique()
array_unshift()
array_values()
array_walk()
array_walk_recursive()
ArrayIterator::current()
ArrayIterator::key()
ArrayIterator::next()
ArrayIterator::rewind()
ArrayIterator::seek()
ArrayIterator::valid()
ArrayObject::__construct()
ArrayObject::append()
ArrayObject::count()
ArrayObject::getIterator()
ArrayObject::offsetExists()
ArrayObject::offsetGet()
ArrayObject::offsetSet()
ArrayObject::offsetUnset()
arsort()
ascii2ebcdic()
asin()
asinh()
asort()
aspell_check()
aspell_check_raw()
aspell_new()
aspell_suggest()
assert()
assert_options()
atan()
atan2()
atanh()

I remember my first experience with PHP way back in 2001. Despite my questionable pedigree in ASP and Visual Basic, browsing an alphabetical PHP function list was enough to scare me away for years. Somehow, perusing the above list, I don't think things have improved a whole lot since then.

I'm no language elitist, but language design is hard. There's a reason that some of the most famous computer scientists in the world are also language designers. And it's a crying shame none of them ever had the opportunity to work on PHP. From what I've seen of it, PHP isn't so much a language as a random collection of arbitrary stuff, a virtual explosion at the keyword and function factory. Bear in mind this is coming from a guy who was weaned on BASIC, a language that gets about as much respect as Rodney Dangerfield. So I am not unfamiliar with the genre.

Of course, this is old news. How old? Ancient. Internet Explorer 4 old. The internet is overrun with PHP sucks articles -- I practically ran out of browser tabs opening them all. Tim Bray bravely bucked this trend and went with the title On PHP for his entry in the long-running series:

So here's my problem, based on my limited experience with PHP (deploying a couple of free apps to do this and that, and debugging a site for a non-technical friend here and there): all the PHP code I've seen in that experience has been messy, unmaintainable crap. Spaghetti SQL wrapped in spaghetti PHP wrapped in spaghetti HTML, replicated in slightly-varying form in dozens of places.

Tim's article is as good a place to start as any; he captured a flock of related links in the ensuing discussion. As you read, you'll find there's an obvious parallel between the amateurish state of PHP development and Visual Basic 6, a comparison that many developers have independently arrived at.

Fredrik Holmström:

Every solution I've ever seen or developed in PHP feels clunky and bulky, there is no elegance or grace. Working with PHP is a bit like throwing a 10 pound concrete cube from a ten story building: You'll get where you're going fast, but it’s not very elegant. ... I love PHP, and it's the right tool for some jobs. It’s just an ugly, cumbersome tool that makes me cry and have nightmares. It’s the new VB6 in a C dress.

Karl Seguin

From my own experience, and the countless of online tutorials and blogs, many PHP developers are guilty of the same crap code VB developers were once renowned for. OO, N-Tier, exception handling, domain modeling, refactoring and unit testing are all foreign concepts in the PHP world.

Understand that as a long time VB developer, I am completely sympathetic to the derision you'll suffer when programming in a wildly popular programming language that isn't considered "professional".

TIOBE index, may 2008

I've written both VB and PHP code, and in my opinion the comparison is grossly unfair to Visual Basic. Does PHP suck? Of course it sucks. Did you read any of the links in Tim's blog entry? It's a galactic supernova of incomprehensibly colossal, mind-bendingly awful suck. If you sit down to program in PHP and have even an ounce of programming talent in your entire body, there's no possible way to draw any other conclusion. It's inescapable.

But I'm also here to tell you that doesn't matter.

The TIOBE community index I linked above? It's written in PHP. Wikipedia, which is likely to be on the first page of anything you search for these days? Written in PHP. Digg, the social bookmarking service so wildly popular that a front page link can crush the beefiest of webservers? Written in PHP. WordPress, arguably the most popular blogging solution available at the moment? Written in PHP. YouTube, the most widely known video sharing site on the internet? Written in PHP. Facebook, the current billion-dollar zombie-poking social networking darling of venture capitalists everywhere? Written in PHP. (Update: While YouTube was originally written in PHP, it migrated to Python fairly early on, per Matt Cutts and Guido van Rossum.)

Notice a pattern here?

Some of the largest sites on the internet -- sites you probably interact with on a daily basis -- are written in PHP. If PHP sucks so profoundly, why is it powering so much of the internet?

The only conclusion I can draw is that building a compelling application is far more important than choice of language. While PHP wouldn't be my choice, and if pressed, I might argue that it should never be the choice for any rational human being sitting in front of a computer, I can't argue with the results.

You've probably heard that sufficiently incompetent coders can write FORTRAN in any language. It's true. But the converse is also true: sufficiently talented coders can write great applications in terrible languages, too. It's a painful lesson, but an important one.

Why fight it? I say learn to embrace it. Join with me, won't you, in celebrating the next fifty years of glorious PHP code driving the internet. Just don't forget to call the maintain_my_will_to_live() PHP function every so often!

[advertisement] Dashboard for Data Dynamics Reports introduces new controls designed to create dashboards that inform without wasting space or confusing users.

Posted by Jeff Atwood    View blog reactions

 

« Twitter: How Not To Crash Responsibly OpenID: Does The World Really Need Yet Another Username and Password? »

 

Comments

Is it not possible to introduce concepts like N-Tier, Unit testing, frameworks to PHP?

I don't think the problem is with the language, but with the communitiy. I like the ASP.NET community more that PHP's. Because PHP''s community seems to be dominated by many "scriptkids" hobbying in in their basements. As a result, there are a lot of bad code examples on the net on PHP. Whereas ASP.NET enjoys much more professional community.

Matthijs on May 21, 2008 04:10 AM

@Matthijs

Have you been living under a rock the last 5 years?
This stuff is all available in PHP5.

Just to name a few main stream frameworks:
CakePHP
Symfony
Zend Framework

The unit testing suit for PHP is created by Sebastian Bergmann.

N-Tier is a way of building applications. It should not be build in a language. It's something you should be able to create with any language available.

As far as the function naming goes. i agree. It's a mess. And even the parameter order for the functions are mixed. Like reversing the needle and haystack. But that doesn't cause bad code to be written. I've been a web developer for the past 10 years. And have seen my fare share of bad coding. Not only in PHP. This has nothing to do with the language. It's because PHP is a trend. So everybody jumps on the bandwagon.

This phrase made me smile though :)

PHP isn't so much a language as a random collection of arbitrary stuff, a virtual explosion at the keyword and function factory.

Thijs on May 21, 2008 04:22 AM

Listen to what inventor of php Rasmus Lerdorf thinks...

http://itc.conversationsnetwork.org/shows/detail3298.html

Edward on May 21, 2008 04:24 AM

What is wrong with wanting beauty for beauty's sake? It is good to have languages and tools that do not make you queasy all the time! For the reasons you mentioned, I am glad that I do not have to use PHP on a regular basis.

That being said, I do find that I can accomplish a lot in PHP with just a few lines of code. It just always feels like an ugly solution.

Vadim on May 21, 2008 04:28 AM

Facebook’s written in PHP too, I think.

Paul D. Waite on May 21, 2008 04:29 AM

PHP's lack of namespacing from the beginning is probably a major downfall, but you can go too far the other way if you're not careful (just look at the sheer size of Java and .NET's respective runtimes). Namespacing has a tendancy to encourage growth, especially if it's nice and extensible.

Hopefully PHP 5.3/6 will strike a balance here, though.

Personally, I know that nice, structured, designed code can be written in PHP (it's what I do for a living, and I know I'm not alone in that), but I don't tend to go posting code snippets in forums asking for help. None of this is because I'm an experienced PHP programmer, of course, but because I'm an experienced programmer in general—PHP's biggest failing was giving novices who didn't know better enough rope to hang themselves.

Mo on May 21, 2008 04:30 AM

> Facebook’s written in PHP too, I think.

Paul -- thanks. I knew I forgot a big one in there somewhere. Added.

Jeff Atwood on May 21, 2008 04:39 AM

I always thought Youtube was built with Python not PHP.

lubos on May 21, 2008 04:41 AM

Mo:
"PHP's biggest failing was giving novices who didn't know better enough rope to hang themselves."

While I agree that it is a problem giving novices the rope to hang themselves, I believe that this is actually a symptom of an even bigger failing: PHP presents developers an inconsistent environment, because things can be toggled on and off by INI settings.

Magic quotes is a good example here. It's on by default in php.ini-dist and off by default in php.ini-recommended. This means that people who learned on one are going to get it wrong on the other, leading to SQL Injection attacks.

Of course, the correct way for experts to handle it is the use of the magic_quotes_gpc() to see what the current setting is and handling it appropriately.

Another symptom of the same problem is that you cannot rely on anything but the most basic of functions to be present, as most can be turned off at the edit of an ini; either by module by commenting out the module's name or by function using the disable_functions setting.

Powerlord on May 21, 2008 04:41 AM

One huge advantage php has over .NET is the transparency and editability of the source code to front end developers.

Working on a PHP site I can dive in knowing little more than to comment out " and ', and can make changes to id's, divs etc without having to know the language.

However, working on the front end of a .NET site you either have to constantly bother the back-end developers to alter the source for you, or learn a fair bit about the relationships between the controls and the html they output.

If you care about back-end and front-end developers being able to work seamlessly together then php definitely helps.

Rhys on May 21, 2008 04:45 AM

"And I just found out (after everyone else probably :-) that YouTube is
almost entirely written in Python. (And now I can rub shoulders with
the developers since they're all Googlers now... :-)"

Guido van Rossum
http://mail.python.org/pipermail/python-dev/2006-December/070323.html

python on May 21, 2008 04:46 AM

@Mo - Like I said, I'm sympathetic because of my background in "non-professional" languages like Basic, but PHP is almost pathologically bad! Here's one example:

http://www.bitstorm.org/edwin/en/php/
--
Some function names consist of more than one word. There are three conventions for combining these words:

1. Glued together: getnumberoffiles
2. Separated with underscores: get_number_of_files
3. Camel case: getNumberOfFiles

Most Languages choose one of these variants. PHP uses *all* of them.
--

Jeff Atwood on May 21, 2008 04:46 AM

> YouTube is almost entirely written in Python

http://youtube.com/results.php
http://youtube.com/my_videos.php
http://youtube.com/my_account.php

It is believed that Guido is referring to the YouTube backend. It's also possible Google forced a rewrite, as I don't believe they support PHP on their server farms.

Jeff Atwood on May 21, 2008 04:47 AM

The problem is php originally stood for Personal Home Page. And you can see that in the design. They have been adding one layer of functions on top of the other. This doesn't make it a bad language. It just makes it a badly designed language. If you compare it to C# or others. You don't get the feeling of consistency. Especially when you go into the OO interfaces.
Personally, I used it for big projects because it was the only real thing around a few Years ago. Today I would never put up with this mess. I shouldn't have to care about what SQL backend I use. Even with Cake it is just another layer on the onion.

ribalba on May 21, 2008 04:53 AM

I liked this...

http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html

The guy learned MVC using rails but didn't like all the "magic" rails does under the covers so he switched back to PHP and re-wrote his app properly.

adrian_m on May 21, 2008 04:53 AM

I remember the Facebook code leak, which is also coded in PHP. The code was clean and well-engineered.

It's only a matter of who is programming. You just need some discipline.

Vincent on May 21, 2008 04:54 AM

Good post. At least an interesting read. I've been a PHP dev guy on and off for a couple of years now, and I'd just like to point out that I think a distinction needs to be made between a languages ABILITY to be written in nice, neat, OO style, and the general trend of developers who CHOOSE NOT to write it that way.

Bet I can write some C, Java, Ruby, or Perl that looks way uglier than most of the PHP you've seen - that is, if we're nitpicking the way code looks.

Chris on May 21, 2008 04:57 AM

While I was a bit offended by the fact that saying a programmer with even an ounce of talent would find that PHP sucks basically translates to that I must suck because I don't think PHP sucks... I can let that pass, since I'm sure it wasn't your intention to offend anyone ;)


Anyway, while it's true that a lot of PHP code sucks, it's definitely caused by - as highlighted by the other commenters too - the fact that most PHP programmers are hobbyists and "amateurs". I can admit that I was one as well, and my PHP code was as bad as anyones. Today it's a different story, though, as I've actually been coding for so long and in different languages, read books (incl. some that are on your recommended reading list) and so on...

I really like languages like C# and Python, but I can't say that PHP sucks. I've been coding in PHP for over 6 years, which makes it the language I've been using actively for the longest time. After you've been working with something that long, it all actually starts to make sense - but I think that PHP's problems, such as function naming and parameters being inconsistent, and the problems they cause are exaggerated a lot.

Jani on May 21, 2008 04:58 AM

I agree with the first part, not so much with the second. Why do I think that my opinion matters? Because less than half a year ago, I've consciously chosen PHP for a web application framwork I've built. All things considered, PHP was the right choice for the job and the resulting application works very well, has a very clear architecture, is extensible, efficient, separates concerns, models MVC, and generally does all the Good Things that you'd want in an application.

And still, PHP sucked. And it DID matter. A lot. How did it matter? I claim that, had the language been better designed, writing the application would have taken half the time. That's right, half the time. Costing half the money. Which, for a small start-up, is a lot.

Saying that “it doesn't matter” seems awfully cynical. Of *course* it matters and I very much regret that I had to spend any time whatsoever working with that defective tool. The thing is, one of the biggest reasons to use PHP (and the main reason we used it) is its wide spread. If you want to run your application anywhere, you've got no choice but PHP. This actually makes me quite mad: I'm mad in part at the inertness of the internet providers who are unable to provide clearly superior tools in their services, and in equal part at the PHP developing community who expose us to such a sucky tool, and who persist in developing new versions. Guys! Give us a break, stop developing that crap and force the providers to switch to better tools!

It's easy for me to lay the blame at someone else's feet and rant at them but this doesn't my anger any less justified. PHP *is* badly designed and this fact won't change in future versions.

Konrad on May 21, 2008 04:58 AM

> building a compelling application is far more important than choice of language

PHP is cheap. The cost of entry for creating a web app with PHP is something like $1.99 a month + a domain name. You could probably create Digg by copy-and-pasting code snippets found around the web.

If you have an idea, PHP gives you a quick and dirty 1.0 (a la 37signals) implementation for cheap.

My question is how people let a profitable version 1.0 turn into a bloated spaghetti-code 2.0 without at least considering a more elegant and robust language.

Eric DeLabar on May 21, 2008 05:00 AM

The problem with say, cleaning up the functions and putting them into the right namespaces and libraries, is of course that you're going to break legacy apps - unless you allow for the old functions to be used next to the new.

Then, you have to simply force everyone to rewrite their tutorials and books; because when a function is aliased, it does not scream "I AM DEPRECATED, STOP USING ME YOU IDIOT", so people will just use the old one.

Simply by showing that message in a bright red bold font, I'm sure you could solve issues really quickly ;). ASP.Net truly crashes and burns with its Yellow Page Of Death; while it's really handy sometimes that PHP doesn't, it also allows the programmer to be a bit more lazy.

Oh yeah, either make the links of the functions point to something useful, or remove them and just color the font - right now every single one of them links to your archive ;).

Rob Janssen on May 21, 2008 05:05 AM

http://video.google.com/videoplay?docid=-6304964351441328559 re: the youtube architecture. They switched to python a long time before google came knocking. They also use C. But i'm not nitpicking because for the most part you are right.

PHP has its abilities, no doubt. However PHP's ability to scale - code length wise, is just not right. The later PHP's are definately getting better. But look at PHP3. It gets messy quick and thats just the nature of it.

I dunno. I'm sick of these debates.

Mike Scott on May 21, 2008 05:07 AM

> My question is how people let a profitable version 1.0 turn into a bloated spaghetti-code 2.0 without at least considering a more elegant and robust language.

Yes, I can't possibly imagine how that would happen!

http://www.codinghorror.com/blog/archives/000256.html

Jeff Atwood on May 21, 2008 05:07 AM

I love PHP. I don't know why people don't like it, but I don't use the frameworks of the day and engineer everything myself, so my code is elegant and there's an easy transition to blocks when coming from Java and for some reason I just love weak/dynamic typing when working on the web (everything IS a string in the end).

Scott Preston on May 21, 2008 05:08 AM

I have to disagree a little bit. Right now I am working on a small website and a backend admin interface for a local theatre. I have never worked with PHP before and I am learning all the time. I use the Code Igniter framework and the experience has been quite pleasant so far. Example from one of the "views", that produce HTML output from data supplied by the controller:

| if ($acts->num_rows () > 0)
| {
| function acts_to_str ($i)
| {
| return anchor ("admin/play/show/{$i->play_id}", $i->title);
| }
|
| entry ('Acts in',
| ul (array_map ('acts_to_str', $acts->result ())));
| }

This will produce an <ul> list of plays an actor shows in, if any. I think this is quite nice. Forms work in a similar way.

| field ('Description',
| form_input (array (
| 'name' => 'description',
| 'value' => $this->validation->description,
| 'size' => 50
| )),
| $this->validation->description_error
| );

Yes, some programmers can write FORTRAN in any language. I also came to the conclusion that it is possible to write LISP in almost any language. You may then object why not use LISP in the first place. Well, it is not always possible. This particular client has very tight budget and cheap hosting in my country (Czech Republic, but I suspect this is the same everywhere) means MySQL and PHP.

Keo on May 21, 2008 05:10 AM

Has no one else seen the rails crap that is in some of the open source projects? Jeff you are correct, you can write crap in any language despite best intentions.

Imagine most novices trying to write a web application without rails or a framework - thats what most php developers are doing. Its quite an impressive feat when you think about it, what other language is so simple to prototype in? With rails you have to go through many, many more steps to get a hello world, and most non-developers won't bother.
Plus, php is installed on every server on the planet.

php on May 21, 2008 05:11 AM

Make your PHP suck less using this miniscule (60 line) MVC engine; I've used it to develop the web UI on an embedded device manufactured by Cisco, for TimeWarner:

http://code.google.com/p/barebonesmvc-php/

George Jempty on May 21, 2008 05:13 AM

What personally makes me laugh in my mind is how everyone always says how PHP is so badly designed etc., but never can actually show how it slows down their app development. I think PHP's manual is stellar, and it's very easy to find a function for the job and its parameters and such...

No one has really been able to properly argument *why* it is that PHP sucks. The usual issues are always:

- Magic quotes and register globals: anyone who knows what they're doing can turn them off.

- Function naming: while they may be a bit inconsistent, the functions for a specific area (like array manipulation) do follow conventions ok and should not pose a problem for a talented guy (the manual as I mentioned, a good IDE will show the params etc.)

- It just sucks: omigosh, really? =)

Jani on May 21, 2008 05:16 AM

What? Oy! That hurts. I guess now I know how it feels to be a fan boy (or perhaps zealot).

Perhaps it is due to my inexperience with other web languages (with the other being the ASP.NET) but I wouldn't call it a bad language. Certainly, as bad as PHP scripts are, I've seen nightmare code born out of undergrads doing ASP.NET. One might argue that's the undergrad's fault and that they are not really programmers but people using WYSIWYG.

And I argue PHP has the same problems. It's easy enough in that you can hack something up and it works, and given the surge of internet pages, these people may not even be interested in anything but getting the job done. Skip OO theory. Heck, they might even skip functions as merely being "useful". That's why there's ugly perl. And that's why (probably) there will be ugly code for all the new and hip languages (once it get popular enough)

I don't see why good code can't be written in PHP even by just someone who learned proper programming concepts. It's just that PHP is too mainstream. It's the myspace of server side scripting. Perl is probably livejournal. Python and Ruby is probably Facebook or Pownce. (Metaphor falls apart because it suggests there's a lot of functionality differences).

Those who are really interested in programming flock to the 'fun' new languages. Those who left are those who probably don't bother improving themselves and newbies.

I suppose I should be showing pure coding examples, and this may just be irrelevant but I do really think that PHP is not bad and I kind of like it. And maybe I'm just a little nutty and that I love programming so much that I even like the worst one.

M. Firdaus on May 21, 2008 05:18 AM

>> Notice a pattern here?

Yes, but not your one.

PHP hosting is free and everywhere, that's why we see so much PHP apps out there. Now take Python, Lisp, Ruby, Haskell, etc. web apps and you'll have to pay for hosting.

Wikipedia, Digg, Wordpress can easily be done in thoses languages too (even with a clearer code I suppose). We only have to wait to see free hosting companies supporting these languages and PHP will not stay on top for sure!

kib2 on May 21, 2008 05:21 AM

Who learns a language by reading an alphabetical listing of the API?? That's like reading the phone book to learn how to dial a phone. Let's print out the Win32 API's while we're at it. There is a division between API and the language itself. In PHP's case, they're fairly tightly coupled. But it is possible to write PHP without any API calls, it just won't do very much.

The only thing that sucks about PHP is that the barrier to entry is low and the rules are very relaxed. So you get a lot of folks that are barely programmers writing code that Just Works and Smells Bad.

Paul on May 21, 2008 05:23 AM

I think that the problems with the PHP language itself are greatly overshadowed with the quality of code coming out of the community. I'm a professional PHP developer and I have seen a lot of truly awful code written in the language, but I also know it is not hard to right elegant, beautiful solutions.

Stuff like function naming is awful, true, but day-to-day I'm much more likely to be interacting with well designed classes and objects than directly with those functions.

I believe it is the number of amateurs using it that gives us the comparisons to VB rather than the language design itself.

A bit of discipline, keeping to one class per file, putting everything you possibly can in a class, etc. can make PHP a joy to work with. I certainly prefer it to Java, Perl, C++, VB, Ruby... and the languages I do like (C, C#, JavaScript) are simply not as appropriate for the domain as PHP.

Mat Scales on May 21, 2008 05:27 AM

@Paul
> Who learns a language by reading an alphabetical listing of the API??

Familiarising myself with a language's API and object model is one of the first steps I take towards learning a new language.

Is that just me?

Joe on May 21, 2008 05:27 AM

"""
> YouTube is almost entirely written in Python

<a href="http://youtube.com/results.php">http://youtube.com/results.php</a>;
<a href="http://youtube.com/my_videos.php">http://youtube.com/my_videos.php</a>;
<a href="http://youtube.com/my_account.php">http://youtube.com/my_account.php</a>;

It is believed that Guido is referring to the YouTube backend. It's also possible Google forced a rewrite, as I don't believe they support PHP on their server farms.
"""


Let's leave aside the fact that having an url ending with .php doesn't prove anything wrt/ the underlying techno - FWIW, I've maintained a mixed .php / .html url space on my wife's website for 2 full years after migration from a Q&D php solution to a Zope-based one. The point is that the OP wrote that YouTube was "*almost* entirely" written in Python - so what's the point of collecting three urls from the front-end that may - or not - be still in php ?

wrt/ the "forced rewrite" argument, I just don't buy it, sorry. IIRC, Youtube being *mostly* written in Python was public knowledge before Google bought Youtube.

bruno on May 21, 2008 05:29 AM

@Jeff - so I take it you WON'T be using PHP for your new site? You'll be sticking with VB.NET? ;-) I mean Visual Basic 2008...?

VBMan on May 21, 2008 05:31 AM

PHP was crufted together over time and it shows, that's why it is inconsistent, yes it is badly designed, and so it is easy to write terrible code, but it is easy to write terrible code in C, C++, Basic, VB etc ...

So why is it popular?
Because it is a scripting language - No compiling, instant feedback
Because it is forgiving - Aliased old function names, compatabilitt settings etc ...
Because it is simple at first - Like VB it is easy to write simple programs, there is not steep learning curve

All of these attract amateurs, who try and be helpful to other amateurs and so there are loads of 'Getting started' pages and cut'n'paste code samples which give the impression of an amateur language, PHP5 is moving away from this ... slowly ...

Jaster on May 21, 2008 05:36 AM

It's another example of the Worse is Better principle, I believe. The tool the majority uses might not be the best for the job, rather it's the tool these people are the most comfortable with.

Delmania on May 21, 2008 05:39 AM

I like PHP because there is no impedance mismatch to get your idea up and running. PHP has been around long enough such that its supported in virtually every webserver. There is no compilation involved, just create a page and go.

monsur on May 21, 2008 05:39 AM

@jeff

I agree the function naming in PHP is very bad. But it's legacy. And very hard to change and keep backwards compatibility. However camelCase naming is not used in the PHP function names. It's either a complete phrase or _ separated words. In PHP 5 some core objects were added like Date, Reflection, etc. These do use camelCase naming for the methods.

The example comes from <a href="http://www.bitstorm.org/edwin/en/php/">http://www.bitstorm.org/edwin/en/php/</a>;. But i think it's more about case sensitivity then actual function naming.

By the way some of the functions you named in the a* list. Are not core functions. They only become available when loading the extension. This doesn't really have anything to do with your article. But i thought i would provide you with this info anyway. The ArrayIterator methods are not functions. they are object methods. And i guess here you can see a trend in "new" naming convention. All are camelcase.


Thijs on May 21, 2008 05:41 AM

I love PHP =(

=( on May 21, 2008 05:44 AM

The other correlation of your PHP examples is that none of them matter.

I'm quite serious - if any of those sites has an outage, it's annoying, but it isn't mission-critical to anyone. They're barely more than technology demos. If a comment was missing from Digg, who would know? If a page was missing from Google's index, who, apart from the site owner, would know? These systems are error-tolerant in that no-one knows that there is an error.

Over on CodeProject - now rewritten at considerable expense in ASP.NET - we have a community largely of professional programmers that bitches loudly any time they receive an error. There tends to be high visibility of any problems.

Mike Dimmick on May 21, 2008 05:48 AM

A lot of people do use it as a frontend, all right. I tend to suspect that its current prominence is more of a fad than anything else, though; when you look at it first it looks very easy, and webhosts tend to support it. It's a bit of a mess actually writing anything big in it though... It's not a horrible templating system, but once you start doing anything else, things get nasty.

A lot of Facebook's backend is in C++, Java, Python, Erlang and other things, apparently, by the way.

Robert Synnott on May 21, 2008 05:48 AM

My rule of thumb is use php for anything up to but not including login functionality (if your hiring someone to do it). An Average .net dev still costs 40% more than a really good php dev in my experience.

Scott Cowan on May 21, 2008 05:50 AM

Oh, besides that, it has no closures, no namespaces and very weird scoping. Urgh.

I used to use it, by the way; it seemed like a simpler way to write websites than C++ or Java, and I never could stand Perl. Python and Common Lisp were _such_ a revelation.

Robert Synnott on May 21, 2008 05:51 AM

@VBMan Jeff said he'll use ASP.NET Ajax and it's MVC framework for StackOverflow.

Also, nice one, Jeff. This is exactly why I don't like PHP.

KTamas on May 21, 2008 05:52 AM

@Mat Scales

"I believe it is the number of amateurs using it that gives us the comparisons to VB rather than the language design itself."

I don't disagree with that statement, put a shitty programmer in front of C# and his code will be shitty. But PHP itself is full of poor usage - extremely limited use of exceptions, limited use of OO, no sensible framework baked into overall product. I've programmed in CakePHP and it's a joke when compared to other MVC + ActiveRecord patterns. Even so, I'd take CakePHP as a pretty big step up, but the adoption seems to be fractions of the PHP community. (Akelos seems like a much better implementation, but it's adoption is even worse.)

karl on May 21, 2008 05:53 AM

I don't think this applies to PHP only. The .Net framework is probably as inconsistent (in it's own way) as the PHP framework (the language itself isn't that bad, actually). The core of the problem is a functionality overload: there's a function (or class) for about anything. And it's hard to remember all of those.

The major difference between PHP and .Net (for example) is that the .Net framework has an excellent toolset available which migitates a bit of that functionality overload: Visual Studio (Express) and Intellisense. While PHP has those too, they're a lot less visible and available than Visual Studio. In fact: it's harder to start developing an ASP.Net site without Visual Studio than with Visual Studio (even for experts).

So while I agree with Jeff's post, I think there's more to it than he claims.

Inferis on May 21, 2008 05:56 AM

Oh, and no sensible Unicode support. How many modern languages, especially languages targetted towards the Internet, can you say that of?

Robert Synnott on May 21, 2008 06:00 AM

@Rhys
oh ffs... What kind of developer are you talking about?! You can go on a rampage and blindly dump every .net control into an application and don't care about the html code it generates... But it is lousy programming and it gets you to great examples of brainfuck code (http://en.wikipedia.org/wiki/Brainfuck#Commands) in any language!

Wafflecop on May 21, 2008 06:01 AM

One of the problems is that even some of the more well known PHP frameworks are kinda crappy... like karl mentioned CakePHP. That makes everyone who does not bother digging a bit deeper, or those who haven't really looked into PHP for a while, think it's a bad language that can't be used to make anything nice.


There are seriously good frameworks too. Zend Framework combined with Doctrine ORM are a *major* win. They have some very talented people behind them.


Btw, if you listed all the classes/methods from the .NET Framework which begin with A, I believe it would be quite confusing =)

Jani on May 21, 2008 06:02 AM

PHP hosting is cheaper you know.
That is why young web developers almost always use PHP.
When the app they built gets big, it becomes a problem. Thats it.

Niyaz PK on May 21, 2008 06:06 AM

Yeah, those other guys create crappy PHP but mine is elegant and slick.

Ouch! Broke my eye winking so hard.

old fart on May 21, 2008 06:13 AM

To all the people wanting to find more Python, Ruby, etc... on cheap hosts: these hosts will only install what their customers demand. And their customers will only demand your language of choice if there's software they want to use that's written in it.

So to fix the problem, write software people want to use in the language you prefer and release it!

Joseph LeBlanc on May 21, 2008 06:14 AM

no, no and no. PHP 5 has OO and exception handling similar to java and phpunit is very similar to junit (so unit testing is not a problem, only problem is that most of the php developers don't use it).
Because PHP gives you a freedom to write your code in several ways (with php5 you can write pretty good oo stuff), it's easier to write crappy code (or fortran).
I agree about php function names, they are very inconsistent and it's annoying. One other thing i really hate is that there are no consistency about arguments: sometitmes it's func1(needle, haystack) other times it's func2(haystack, needle). Often you have to check reference just to be sure that you are using arguments in correct order.


mart on May 21, 2008 06:16 AM

There is one reflection strikingly absent from all the comments so far: why did ever PHP become the de-fact-choice of all web hosters? Well, it's because of the off-the-shelf php appz, dood! (answer B: it's because that's what the devs asked to hosters). If you go back in time 10 years, finding php hosting would not be so easy. In other terms: demand drives offer - it's just that hosting companies are slow to respond. If everybody asks for python now, they will have it cheap and easy in 5 years time.

I found the post very funny, but mostly agree with Ilia - a bad language is not such because of a humongous function collection or inconsistent parameter ordering. The online, user-commented php manual was php's gift to comp science, and by itself it solves the function naming problem.

A good language otoh makes the simple things trivial and the hard ones simple. And few things can beat php at that (and few other communities have produce such a boatload of really, really crappy code that is still good enough to run the web).

gaetano on May 21, 2008 06:16 AM

I still enjoy PHP from time to time. It's almost universally installed on webservers and if you need to make a quick web app it takes second to throw one together. Last year, I rescued a mailing list for a bar owner/friend. We created a simple 10 line query to pull the entire list into a csv file. Import into Excel and some clean up and now he's got a useable mail merge for his office.

Over the years I backed away from PHP: 1) .NET developer jobs were paying 10K+ for equivalent positions. 2) I liked the cleanliness of having namespaces and real typed variables. 3) Until PHP5, OO felt like a loosely bolted on 5th wheel. It was there but few were using it correctly or at all.

I do believe there is less noise and better coders in the .NET camp. On the freelance level I was competing for cheapskate businesses who wanted good websites but paying scriptkiddy money.
My experience has been that someone that pays for a dedicated server, IDE, and SDK is heavily invested in their idea. Anyone can get a $10/mo server that does little more than PHP and MySQL and scoff at that idea that a good developer is going to cost $1000s

Joe on May 21, 2008 06:19 AM

All programming languages suck. They just suck in different ways. The sensible programmer knows it's all about 'horses for courses' and uses what's appropriate for the task at hand.

Pascal and Ada are examples of a languages that were created to be philosophically pure. PHP and Perl are examples of languages that were originally created as duct tape to get jobs done. Oddly enough, the latter are more popular than the former, despite the objections of anal retentive purists.

Rather than bashing a language for its historical legacy, Jeff, how about you mention how you would make the best of things in PHP to produce a good PHP application. I'm sure that would benefit your readers immensely.

Pete on May 21, 2008 06:19 AM

@mart:
I think you're missing the point. It isn't that PHP doesn't have support for those - it's that most PHP developers don't leverage them nearly to their fullest potential. In fact, the PHP library itself doesn't.

Karl on May 21, 2008 06:20 AM

To both gaetano and Joseph LeBlanc, it has nothing to do with the apps. The apps exist because the hosting exists.

Apache is the defacto standard for web servers, Apache runs PHP pretty efficiently on commodity hardware. PHP is easy to install, easy to maintain, easy to deploy to, and VERY easy to host.

Java, Rails, Django (I think?), and .NET cannot make those same claims. I know personally that a Java app written to the complexity of something like Wordpress would require its own server, not something a web host is going to be very interested in hosting for $1.99 a month. Rails on shared hosting is flaky at best (anybody ever tried it on Dreamhost? Not pretty.). .NET requires MS, in theory anyway, that means licensing costs.

PHP is everywhere because it's cheap and easy for everyone.

Eric DeLabar on May 21, 2008 06:26 AM

The major advantage of PHP is that you never run into something you can't do. At least I haven't. And I do all kinds of crazy stuff. Websites, Intranet utilities, it talks to everything and with very little research it just works.

Rails? Ha! Waste of time. Only if you want to write nothing but blogs and demos (which most do). Sure it makes the designers happy, but I am not a designer. I want to do MORE.

Python is a fine alternative. I think it's practically the same language with different syntax.

But yes, it is inelegant. Very inelegant. And how elegant your code is—is totally irrelevant.

Jeff Davis on May 21, 2008 06:27 AM

functions are not part of the language, if you don't like the functions name, it doesn't mean that the language is not good.
It's like complaining that C is a bad language because of the standard library, use your own functions, name them what you want.
I find PHP a great language.

Petruza on May 21, 2008 06:28 AM

As Bjarne Stroustrup once said "There are only two kinds of languages: the ones people complain about and the ones nobody uses."

Roger on May 21, 2008 06:29 AM

PHP is simple and fast. In many ways, due to the awesome online reference, it's easier to figure out how to do complex things with PHP than with other more popular technologies like JSP/ASP. Also, due to the RAD design of technologies like ASP.Net (which I have done professionally since it was in beta), they are slow and clunky. Sure, if you avoid using postbacks and the control tree, you can reach the same performance levels PHP provides, but I rarely see that done. Because PHP writes directly to the response stream still like old ASP did, it encourages the old coding styles which in turn gives better performance. PHP's lack of packages/namespacing is indeed a problem, but the only way to get rid of that is to fork the project into PHPlus or something like that, and organize all of the functionality into logical groups, standardize naming conventions, and re-release it with a converter program that will convert old PHP to the new PHP. Without a converter, it would be doomed to fail.

Justin on May 21, 2008 06:30 AM

Dear Jeff,

PHP started as a language designed to add flexibility for serving HTML content on http calls. One http call = one run. This means for the complex web applications we are using now: you basically need to re-initialise the whole application on each call in one state, bring it to another state, output content and save the state, if necessary. This is inefficient. AJAX is only haf a relief because you need not to send the whole page anymore, just the bits that change.

For me, the problem is beyound: why do developers choose with PHP an application model for the system they want to create that does not support object caching and view-based state caching in an efficient way itself? For me, application development starts before: build an abstract software model and decide then, which kind of application model suits it best. And this is something you do not usually learn when learning to program.

So long - Tobias

Tobias on May 21, 2008 06:31 AM

If in any language one can write beautiful code (with that I agree 100%) I wonder what makes some laguages produce sphagetti and others lead to good code.. For instance PHP and Perl tend to be maintenance nightmare, while Java and Python source code is much more maintainable.

- is it low entry barrier? (Perl has high barrier to entry)
- or too fast learning curve? (python is quick to learn)
- or maybe standard libraries influence programmers (but Java had an old collections framework that was ugly but that didn't pollute programmers' minds worldwide)

What is the reason most successful frameworks like JUnit, Spring, Hibernate happen in Java world first before being ported to .NET, Ruby, Python, PHP? Is it that majority of experts and creative people do mainly Java? Or perhaps there is something in the language that stops developers from bad practices and enforces them to seek for better solutions? Or in problem space they deal with? Or perhaps in the platform, or in the ecosystem around given language? Or in books that people start learning the language from?

So, which of these you think contain core root of the problem?

There are a lot of upcoming new languages like Groovy, Scala etc, what should focus their creators on to minimalize the risk of them evolving to another maintenance nightmare? Perhaps it would be easaier to anser "opposite" question: how to design a bad language that will result in tons of mess?

mantrid on May 21, 2008 06:32 AM

It's worth pointing out that in addition to some of the other big names mentioned above, Yahoo! also standardized on PHP some years back, and, as far as I understand, many of their properties have been built using it.

Roger on May 21, 2008 06:33 AM

The unfortunate fact of the matter is is that PHP is that is virtually on every server in the world. Why? Because its really easy to deploy with no hassle. This means that PHP is not going away anytime soon.

While I agree PHP is ... crappy (to be nice :) ... it has its ups in that the time to market for php code is extremely fast. In the past couple of weeks, I've made quick apps that work just fine with PHP. I would never create a large scale app with it, but for quick and dirty things, it's pretty ideal.

Benny on May 21, 2008 06:33 AM

The unfortunate fact of the matter is is that PHP is that is virtually on every server in the world. Why? Because its really easy to deploy with no hassle. This means that PHP is not going away anytime soon.

While I agree PHP is ... crappy (to be nice :) ... it has its ups in that the time to market for php code is extremely fast. In the past couple of weeks, I've made quick apps that work just fine with PHP. I would never create a large scale app with it, but for quick and dirty things, it's pretty ideal.

Benny on May 21, 2008 06:34 AM

There are two egregious logical fallacies in your argument. First, by attempting to use facts to make a case for the languages goodness or badness, you commit a naturalistic fallacy. PHP doesn't suck because it allows you to write function names in three different ways. It does not suck because you consider it ungraceful. It does not suck because crappy coders use it. By the same token, it does not *rock* because its used by some of the biggest web properties.

Secondly and to a lesser extent, you've got a "post hoc ergo propter hoc" (after this, therefore because of this). Just because you used what some consider to be crappy languages in the past, does not validate what you are saying now about PHP. While I can understand and appreciate the effort to "commiserate," I fell it is expressed under false pretenses.

Plus, to be perfectly honest, we PHP developers don't need it. I find PHP to be a tremendously effective language, blending all the useful parts of C, C++, Java, and Perl (which also contributes to its hodgepodge nature) to tackle the monster that is the web. I have no trouble reading it, but then again I build on the platform professionally, full-time, and write in an excessively clean fashion.

The lack of concrete evidence to support your argument, and the overriding presence of pure opinion-based references, makes your argument look like nothing more than fanboy ranting. If you're interested, I'll have a post up on my own blog to counter your arguments pertaining to the language's utility later this week.

This is two posts now where I think you've gone off the rails, Jeff. I hope you won't make a habit of this. ;-)

Frank on May 21, 2008 06:34 AM

Without reading all the other comments, and as a long time PHPer, let me first agree that PHP is messy. The reason I got into PHP was the low entry barrier. It is not a disciplined language. It's very easy to get started and thus you can find a bunch of junk code and duct-tape solutions.

But in that same stroke, getting good at PHP actually requires discipline. I'm not claiming to be a PHP guru, but I've written many, many enterprise-level web apps that have stood the test of time and that have helped many, many people. I spent time studying "good" programming practices from other languages and did my best to apply them to PHP. And it worked pretty well.

PHP is powerful and can do a lot, but that doesn't distinguish it from other languages. In fact, nothing does - shy of it running some of the most popular sites on the internet. But again, I would suggest that choice was made due to the availability (and free-ness) of PHP. It's a very low overhead language.

But I suppose in the end, what's it matter? I know it sounds like a cop out excuse, but ASP, PHP, Java...they're all just tools. Thing is that if it were not for file extensions, we wouldn't know what any web site/app uses.

I've made a nice living working PHP magic. If you actually take PHP beyond downloading and installing pre-fab software, it's extremely handy. But since it doesn't force you to learn proper programming methods, you actually have to learn them and understand them. Something you might not get from IDE and languages that do it for you.

Morning Toast on May 21, 2008 06:35 AM

Jeff - I'm having a hard time agreeing with you. I have several reasons - but keep in mind that I have limited .NET experience (I've never taken the time to learn it/use it)

I agree that PHP feels like a hodgepodge of functions that have been pieced together. However....
A couple of years back, I was using the (choirs of voices in the background) all-powerful **Java** language to code a website. The use of beans was pretty cool and I enjoyed basically having the full power of Java at my fingertips. That was when a funny thing happened. I had to handle a file upload. OMG!!! JSP had no default means to handle a simple multipart/form-data submission. I had to build a whole crap-load of header-parsing nightmare just so my users could upload a stinkin' image. What a pain. Arrays? What a joke. An array could have an int as an index but not an Integer? (they are different, of course) - 1 is not the same as 1 in Java, I suppose.

So I learned to hate Java pretty quickly. I eventually wrote version 2 of the app in PHP. My file upload problem was solved with the global $_FILES collection without any extra coding. Arrays could be associative with the same array() function and I could sort and all that.

For some reason, PHP just *feels* like it was made for the web...and only for the web. Java and .NET are like hybrids that allow me to write a web app or a windows app with the same language.

I can use a screwdriver to put in a screw and the handle to pound in a nail; but shouldn't I just use a hammer for the nail?
</bad_metaphor>

Jon on May 21, 2008 06:38 AM

PHP always reminded me a lot of classic ASP.net... not structured as well, but the way it worked and made a mess of spagetti code. ASP thankfully evolved into ASP.net, PHP is still PHP.

I've got to think it's wildly popular because it's really the best option you have for sites using Unix. You don't see very many Windows developers using PHP.

Let's at least agree that it's a step up from using Perl to create interactive websites.

Kris on May 21, 2008 06:42 AM

I meant to say "PHP always reminded me a lot of classic ASP" in that comment... not sure why I tacked .Net onto the end of it. Oops.

Kris on May 21, 2008 06:43 AM

I don't usually comment on your blog, but I read them every chance I get. Anyways, I code professionally in C# and VB.net, but I use PHP every chance I get for personal projects. Why? Because, PHP is streamlined for the web and has built-in functions for just about anything I can think of to make building a dynamic website easier.

I'm able to get a nice, cleanly written, fast and functional PHP built site in half the time that it takes me to do the same in C# and .NET. Combine PHP with Apache and MySQL and I haven't found anything I like better.

I don't think you can say the language sucks when so many of the best & biggest sites on the web run on it. You can say the programmer sucks though. I look back at PHP code I wrote 5 years ago and its a mess, but today I follow a lot of structure to my code and feel that its just as managable as anything I've written in C#.

I have a Halo 3 Multiplayer stats website, http://halocharts.com, that is written in PHP that's getting over 3000 unique people a day and tracking over 50,000 players. It would have taken me months longer to write the same site in C# and SQL Server, plus all of the licensing fees would have been a pain...

firestream on May 21, 2008 06:44 AM

I see PHP as a language that allows choice. I started with PHP out of necessity to get a job done. It was either PHP or ASP, and I was leaning toward ASP except I could find absolutely NO documentation on the net for ASP at the time, but more than enough for PHP.

PHP also let me choose my OS and my web server platform, which ASP did not. I'm a big proponent of choice.

You're right. I can code spaghetti code really quickly in PHP but I don't have to. The language let's me choose my programming style. I can (since PHP 5) go the object oriented route or complete procedural if I want. I can code sloppily or code extremely cleanly -- it depends on me. The function_list_that_goes_on_forever seems to be the same as the namespace.that.goes.on.forever, just a different convention.

It's choice. I'm grateful I have it to make. I choose to code responsibly and be wise in my coding convention, commenting and holding to an overall convention. If other people do not, then they've made that choice.

Danlb on May 21, 2008 06:49 AM

Think of the most popular and remarkable human cities; Paris, New York, London, and so on. Now think of their grunge; all the urban decay, trash dumps, and on and on. PHP is architected more like a human city than a piece of sculpture or painting. It may be that the crystaline precision of mathematics or formal art doesn't scale to human community sized endeavors, like New York or YouTube. PHP may be grungy, but so's most of the best stuff people actually use, as opposed to what people admire.

Pat Morrison on May 21, 2008 06:49 AM

I think most people forget the Human Factor. The #1 reason IMHO that php is so popular is because it brings the productivity to the human side. In Java and other older languages, you have to learn one of the bazillions of frameworks out there and hope that the framework does what you want. When you remove that factor, the speed that a developer can code (without errors of course) is linearly proportional to the speed he gets new features out. You want more features, just have to type faster! Haha!

Developers feel better if they think that the bottleneck of productivity is on their side, ie, one only needs to transcribe mental ideas to code to create new stuff, instead of having to learn some new API in an unfamiliar framework just to produce a Hello World. The problem is, not everyone is brilliant and almost everyone creates bad code. The difference between php and say java is that some of the components of an app (db acess, controllers, etc) are already solved out in a reasonably way for you if you use some framework.

IMHO frameworks like rails or grails managed to balance the needs of most common web app aplications into the framework itself, so that the developer effectively gets things done with minimum effort.

As for the maintainability myth, my view is that maintanability is much more design/architecture related than language related. Code aArchitectures normally don't scale in the sense that adding new functionality becomes more and more harder, instead of being a constant value.

My .2 €

Miguel Ping on May 21, 2008 06:50 AM

The great thing about PHP is its freedom. Professionals can use it in a growing industry, as well as "script kiddies" can use it in their mom's basement.

The structure and maintainability of the code is largely dependent and determined by the skill of the programmer. The way it should be...?

I am personally tired of hearing Microsoft fanboys denounce the PHP language for flaws that it had in version 4. Maybe you haven't checked in sometime, but version 5 is now out in production.

"If you sit down to program in PHP and have even an ounce of programming talent in your entire body, there's no possible way to draw any other conclusion. It's inescapable."

Wow, ignorance is bliss. I don't think you are qualified to come up with statements like this when you say you are a Visual Basic programmer. I have programmed in Visual Basic before, and I thought I was losing intelligence throughout the entire experience. A Visual Basic programmer, is a lazy, ill-informed programmer. That's just my two cents anyway.

I could be partially biased however, because I work with a VB programmer, and he doesn't know how to "write" code. He copies C, C++, and C# scripts from the internet, and runs them through a X to VB converter. Obviously that makes some pretty (sarcasm) code. ;)

Douglas on May 21, 2008 06:51 AM

So your argument is, essentially, that PHP is OK, because all the cool kids are using it?

Jacques Chester on May 21, 2008 06:52 AM

Why is a language bad? The worst crap I've seen many times was in the revered C++. Some of my best code in college was in Fortran, for crunching numbers. The Paradox Application Language (PAL) for DOS was completely logical and stylish.

Perhaps we judge a language based on the (pseudo) framework it's used in? I despise .NET Master pages and the mangling that occurs when the page is assembled and my viewstate is mis-placed. Case sensitive languages are retarded. Ruby is good but Merb is a better framework than Rails?

In the end it's what @monsur referred to as low "impedance mismatch", then it's the reliability, maintainability, etc., that the language offers.

steve on May 21, 2008 06:57 AM

I think the whole argument here makes a very big mistake! It mixes language and API. So do most articles you quoted or linked to.

This is a big mistake most people usually do with Java.

int i = 10;
String s = "Hello World";
Object o = new Object();
float[] farray = new float[20];

This is *language*.

ArrayList ar = new ArrayList(20);
Iterator it = ar.iterator();
JPanel jp = new JPanel();
jp.getContentPane().add(new JLabel("Hello World"));

This is not! This is *API*.

PHP as a language is very clean, has very little elements. It defines a couple of data types, primitive operation on them (add, sub, mul, div, and, or, xor, etc.), it declares functions, it declares objects, arrays and hashes.

The huge amount of functions, with inconsistent namings and unexpected behaviors because two similar functions might have entirely different behavior, these are all API. They are the default API, that means they are there on a fresh PHP installation without installing any plugins; but they are not really part of the language itself.

I admit, while it is very clear what is language and what not for other languages like Java or Perl (because this is documented), the borders are pretty blurred for PHP. However, PHP is not the only language where the borders are so blurred. Another familiar one, and probably mostly used language in computer technology today, is C. E.g. this is langua in C:

char * buffer = calloc(sizof(char), 100);

But C does not guarantee int's to be 32 Bit, so programmers like to go there and do

u_int32_t num = 10;

or

uint32_t num = 10;

and when you want to open a socket (for network data transfer), they do:

int so = socket(AF_INET, SOCK_STREAM, 0);

However, this is all not language. No C compiler in the world needs to successfully compile that. u_int32_t is actually nothing at all (where the heck does this come from? Only because it's there on most system doesn't mean it has a right to exist). The only thing the C standard specifies is int32_t, that is signed, not unsigned. uint32_t is defined in the POSIX Standard, but not every platform that supports C needs to support POSIX (many don't support POSIX). And the socket function is also only defined in POSIX. Linux is mainly POSIX compatible, so is MacOS X, but Windows for example is far away from being POSIX compliant.

Long post, short summary:
It's not PHP that sucks here, it's the default API of PHP that sucks, because of all the negative issues quoted or reported on other pages.

Mecki on May 21, 2008 07:03 AM

I agree with Jon's comment above, about PHP being a "WOP" (Web-Oriented Programming) language. People often ask rhetorically "But *why* is PHP so popular for Web programming?". Clearly, it's not because PHP is elegant from a formal language design point of view.

Just take a look, for example, at O'Reilly's "Learning" series of books. Compare "Learning Perl" and "Learning Python" with "Learning PHP5" (I'm doing it now using their Safari service). The first two barely address Web programming at all (at least not explicitly on the contents pages) and are clearly general purpose programming/scripting languages spiritually at home on Unix and derivatives. The PHP book, on the other hand, has a few chapters on language basics, and then gets right into processing forms, connecting to databases, managing user session, processing XML and uploaded files, etc. It has appendices that include information about configuring IIS and Apache, and the book doesn't assume its audience is is using or deploying to Linux or BSD.

This difference of emphasis is played out across the publishing industry and online resources, it's reflected in the nature of the advocacy for the respective languages, and consequently I don't find it surprising at all that PHP is used so frequently for web programming.

Roger Lancefield on May 21, 2008 07:08 AM

My main gripes as a PHP dev: no console and no first-class functions. I do like, though, that *the* data structure in PHP is an ordered dictionary. If the array functions were namespaced, "import array" would be as cool as "import antigravity"; you get a queue, a stack, a dictionary, and a list in one.

Braden on May 21, 2008 07:08 AM

Just because it's easy/possible to create spaghetti code doesn't mean you can't create efficient and maintainable php apps. My apps are object oriented, business logic is separated from the html, and I probably only use 5% of those 'a' functions.

sgb on May 21, 2008 07:08 AM

Funny, I've written a PHP Sucks article myself (and got lambasted for it) but I've put together one site in PHP and am starting another one and yes PHP still sucks, but you can get a lot of work done in it. I debated Java vs Ruby for my new site for weeks and finally decided, I'm tired of debating with myself, just get it done in PHP.

codist on May 21, 2008 07:09 AM

At my very first ever job as a Professional Software Developer(tm), I had to maintain a PHP app. I sometimes have nightmares about it.

Grandy Peace on May 21, 2008 07:10 AM

Why is pascal getting popular again?

Goran on May 21, 2008 07:14 AM

I'm not going to make dumb generalizations about everyone who writes code with PHP but it does seem that the way the language is designed really does encourage sloppy and procedural style code. I believe that better language design would help a lot with the quality and maintainablity of PHP projects that are available.

o.s. on May 21, 2008 07:14 AM

@steve:
Some languages are bad because they limit, restrict or force your choices. Take the example of namespaces. In a language without namespaces, I have to find a way to avoid name collisions. In a language without closures, you can't pass code encapsulated in a closure. That forces you to solve the problems using a solution you consider not to be the best. This is where some design patterns might help you out, they are a cristallization of a solution for a problem on a unique domain (example being multimethods and the visitor pattern).

OTOH, the more power you have the more rope you have to hang yourself into.

Miguel Ping on May 21, 2008 07:20 AM

Languages don't much matter. Programmers do. Garbage in, garbage out. A language doesn't magically transform your application into a work of art.

Bitter on May 21, 2008 07:21 AM

@Mecki

That defense is old in the tooth. Who cares if it's the "language" or the "API" - we all know what Jeff is talking about. Even the pro-PHP comments here admit that there's something less than ideal in the PHPsphere.

Besides, can't the problems in the library potentially be attributed to the language? I mean, if you want to draw lines in the sand and make the argument about language vs library, PHP is a good language, but is it a great language? I mean, no closures, no pure OOP (maybe you consider that a benefit, i don't), no mixins (i have seen hackish implementations), namespaces, late static binding (coming soon), horrible scope resolution (you need $this-> infront of everything..)

So even if you are right that we're all mixing library from language, it doesn't magically make all the problems of both the library and the language go away.

karl on May 21, 2008 07:22 AM

PHP Bringing order to the madness: http://www.qcodo.com/

Javierfish on May 21, 2008 07:25 AM

i think the great skill with languages like php (such as 'classic' asp) is to "program into the language" not just program in the language.

This is a Steve McConnell idea -- he harps on about it on every second page of Code Complete.

i've seen some very well structured, somewhat beautiful classic asp -- and it shows great discipline on the part of the developers.

lb

secretGeek on May 21, 2008 07:28 AM

Since I was quoted in this post, I figured that I would make a contribution to the steady stream of comments.

In my opinion PHP sucks because:
a) Incredibly inconsistent naming
... 1) Mixing of underscored and non-underscored
... 2) Inconsistent abbreviations, e.g: using "i" or "case" to imply case-insensitivity

b) Somewhat inconsistent argument order
... array_map(func, arr) vs. array_walk(arr, func)

c) Expression de-referencing
... Meaning doing something like: "echo (array(1,2))[0];" will fail miserably. Except that it works for object references... IN SOME CASES, could it get any more inconsistent ?

d) No (proper) support for lambdas or closures

e) No support for namespaces, yes it's coming in 5.3/6 but it should've been there from the beginning - in maybe 3-4 years we will be able to use namespaces in production code.

f) Usage of array() instead of a simpler syntax such as [] or {} for creating arrays, which makes it incredibly ugly and hard to read when you need to nest several arrays

g) Usage of -> instead of . as the object operator, this is actually more a convenience concern then aesthetic, writing -> (at least on Swedish keyboard is a PITA)

h) Incredibly old fashioned object model, it got a worse feature set then Java had back in -96. They've tried to launch PHP as an "OO"-scripting language, right.

i) A lot of functions that mostly do the same thing, takes the TIMTOWTDI to a whole new level.

There are a couple of more issues for me personally, but these are the nine main ones. And all the issues with the "hobby" community, etc.

So yeah, PHP sucks. However I still use it because it puts food on my table and pays my bills.

Fredrik Holmström on May 21, 2008 07:31 AM

This same argument was once used for COBOL. PHP will eventually be replaced as COBOL was. Sad thing is, it will take very long. Even today COBOL struggles on some reincarnations.

jm on May 21, 2008 07:36 AM

Isn't the classic "but you write PHP that doesn't suck" example Drupal? It usually comes up in these kinds of discussion anyway.

hpr122i on May 21, 2008 07:36 AM

It's patently clear very few people posting comments here (or Jeff) has used PHP any time recently. There's no other explanation for the foolish and incorrect things stated here.

I used PHP in 2001. It was slapdash. Using it as a comparison is called a "straw man." Boo.

I use PHP in 2008. It's got everything you need to build stable, well-designed, scalable apps. Period.

The *only* legitimate complaint I have ever seen about the language itself is lack of namespacing. Welcome to PHP6.

There's nothing wrong with the language.

People who use it poorly have themselves to blame.

Kyle Hale on May 21, 2008 07:36 AM

As someone who codes VB6 and PHP pretty much exclusively (though I have gone on to VB.NET, 'cuz it was free and all), I just want to say that my goals are never to be elegant. My goals are to be quick. I am an experimenter, a tinkerer. I am not a computer scientist by training. I am a historian who can code a bit.

Having languages like VB and PHP allows someone like me -- who doesn't want to do memory management or worry about callbacks and etc. -- to quickly throw together things that other people won't. Can I beat the computer scientists when it comes to writing efficient code? No way. Can I beat them when it comes to writing code I can use? That's the whole point.

So what's my point, in the end? The people who bash PHP aren't taking into account the crucial social aspect of it. Why does it matter that Wikipedia and Wordpress are written in PHP? Because practically anybody can work on them. In a land where processor time is cheap, the ability to quickly modify an existing program is king.

I write my own database interfaces in PHP because the off-the-shelf programs for historians, like EndNote, suck a big one, in my opinion. They aren't set up for me and they can't be customized to my needs easily -- something that's a big problem in the humanities, because my work doesn't fit into nice little boxes each time. Each project has its own needs and considerations. A well-structured program is, well, a little too well-structured. Something made out of PHP can be mashed about, changed, new things added quickly, etc., on the fly. And it works.

Should an entire OS be made out of languages like this? Should critical programs be made out of languages like this? No way. Should programs that place a high, high priority on being easy to edit by people without CS degrees be made out of languages like this? Yes. And _of course_ that's going to bug people with CS degrees -- PHP makes those of us without them think we can nudge you out of the picture. ;-)

Shmork on May 21, 2008 07:36 AM

PHP is successful for exactly the same reason VB was successful: they both made a simple thing very simple while no-one else cared.

Unfortunately both sucked in every other possible aspect, thus repelling most good programmers and attracting hordes of bad/amateur programmers, building a huge environment of crappy coding standards.

And unfortunately PHP still has a big selling point: want to do a web app that you can install everywhere? Do it in PHP.
And so we are stuck with PHP for a long time.

Also, it is true that a bad programmer can write bad programs in every language, but the reverse is not true.
- If you don't have namespaces you are stuck with adding 'whatever_' in front of all your functions,
- if the language doesn't have a consistent naming convention you can pick one, but you will still live in the mess
- if (for example) you don't have function pointers or first class functions you are stuck with doing the big 'switch' statements
...

E[X] on May 21, 2008 07:38 AM

Having used PHP 4 for some years on my own site, and PHP 5 to make a website for a small company, I'd say there are lots of reasons why PHP is a good idea:
- The "User contributed notes" are actually useful and usable.
- There's no "architecture astronaut" tendencies - The simple option is usually the default, while more advanced functionality is available with more parameters or other functions.
- The web pages are better than for .NET - Faster, much tighter hierarchy, no JS bugs to break the whole site in Firefox.
- It's platform independent, open source and Just Works.

In short, it's built by developers (so it's messy) and for developers (so it actually works).

Victor on May 21, 2008 07:40 AM

"SQL wrapped in spaghetti PHP wrapped in spaghetti HTML", you got it in one. The whole thing is a mess...

kcg on May 21, 2008 07:41 AM

Everthing suck, Windows, Linux, UNIX, BSD, Mac OS all suck. Operating systems suck. Languages suck. With that in mind you are left to question yourself, what does suck less for my purpose?

Hoffmann on May 21, 2008 07:46 AM

so I should learn PHP now ? :)

For me the syntax is just as important as the framework and for me the php syntax was never somthing I felt comftable with. But again alot has happened.

Peter Palludan on May 21, 2008 07:50 AM

"As someone who codes VB6 and PHP pretty much exclusively (though I have gone on to VB.NET, 'cuz it was free and all), I just want to say that my goals are never to be elegant. My goals are to be quick."

Someday you'll have to maintain some code written by someone with the same goal.

Charles on May 21, 2008 07:53 AM

Another one for the list... Flickr is also developed using PHP.

As other commenters have mentioned, PHP is vastly available - almost all shared web-hosting supports it! Which is why a lot of open-source apps are developed in PHP, (quick-n-easy deployment).

I think a root cause of poor PHP coding practices comes from the lack of an established IDE. (I know of Eclipse, but never used it). Could you imagine developing C# without Visual Studio?! (No thanks, I want my IntelliSense!)

A good IDE goes a long way towards guiding coding practices for would-be spaghetti developers.

Lee Kelleher on May 21, 2008 07:57 AM

I love these discussions.

First off, I'll agree with the Jeff here. I'm not going to stand here and say that PHP doesn't have it's drawbacks and it's flaws. But it is successful for one MAJOR reason, it WORKS and works easily.

Hey, I can be a very disgusting coder if I really want to be. No matter the language I can spew out some very nasty code. So I'm really fed up of people blaming the language for their crappy code.

Because PHP is so light weight, it makes it easy to get stuff out the door with less of the safety measures that would be required in other languages because the thing compiles. That's why you have people sticking an entire application in one index.php file that works off of URL parameters.

Also, people need to realize that ASP.NET is a FRAMEWORK and not solely a language people. PHP is only a language. Frameworks such as CakePHP are now evening out the playing field a bit.

Now, I can't help but comment on this dude (cdbaby.com?) that scrapped 2 years of Rails to "code it properly" in PHP. I don't even know where to comment on that. Anything can be coded in any language, but it escapes me how a Framework like Rails didn't seem to satisfy his needs.

3 years ago if you'd ask me what I'd use to start a web application, I would have said ASP.NET. Because that's all I knew that had a high enough level to take me away from all the grit work. But that's because I didn't know about things like Rails and CakePHP. Right now, CakePHP is at the top of my list. It gives me the high level I want in a framework (really, at this stage I don't need to be messing around with pretty URLS and crap like that. Also, unless it's real complex and need to be hand written to be efficient, I'd rather stay away from SQL. Not because I'm scared of it, but because 'select blah, blah from blah' get's old after the 5th time) and the get up and go that PHP allows.

I'm sorry, I agree 100%, PHP may suck, but who cares? It works! It's much like what I've said before:
<a href="http://www.webdevelopment2.com/choice-web-development-framework-matter/">http://www.webdevelopment2.com/choice-web-development-framework-matter/</a>;

Baz L on May 21, 2008 07:59 AM

Jeff, have you read how the TIOBE index is compiled?

From their site:
"The ratings are calculated by counting hits of the most popular search engines"

That is NOT the same as counting the number of sites built in a language. Nor is it an indication of the number of developers working in a particular language. After all, Java coders might need to do more google queries than C# coders...

Never mind the fact that PL/SQL, MySQL (not rated), and Transact-SQL queries make up less than 0.71% of the total. Using your logic, the implication is that less than 1 out of 100 programmers use a database backend...

Further, going from "Some of the largest sites..." to "...powering so much of the internet" takes a bit of mental gymnastics.

Chris Lively on May 21, 2008 08:06 AM

After years of avoiding php, because of all the ugly examples I had seen, it quickly became my favorite web language. Apart from the dollar signs, it works well with how I think. All my php code is short, clear, and fast. Almost all the things I had to write from scratch before are built into the language.

http://www.oreillynet.com/ruby/blog/2007/09/7_reasons_i_switched_back_to_p_1.html

David on May 21, 2008 08:07 AM

As one who has been working with PHP since the mid-90s, I can say with absolute certainty that my comfort level with the huge array of built-in functionality, as well as my memory of needle/haystack mixups throughout are both quite high. I can work quickly and elegantly.

The ego I am reading here in the comments is not surprising to me. An awful lot of people complaining about PHP circa 2001, and not looking at all to the future of this dynamic, useful, broad-reaching language.

But if you want to keep bashing it because it's not branded with a giant corporate logo, or doesn't come with its own IDE, or has no built in make_website_work() functions, fine.

Stephen on May 21, 2008 08:09 AM

I agree completely.

Programming skill is the important thing in php. You can build ur program completely scalably with code reuse etc, or you can build a nice bowl of spaghetti. I've written some php and using simple OO patterns you can have very elegant looking code ... or not.

mordy on May 21, 2008 08:12 AM

"SQL wrapped in spaghetti PHP wrapped in spaghetti HTML" - That means that you suck, not the language. And does this also mean that HTML and SQL arent any good?

This is obviously just an emotionally charged rant. Its also missing information - You seem to have no idea that there are MVC frameworks for PHP. And speaking of that, your article a while back on MVC sucked too. Oh well

PHP is everywhere
PHP is free
PHP is fast
PHP is feature rich
PHP is well supported
PHP has an excellent user base
PHP has many community developed tools
PHP is well documented with an excellent online manual
PHP isnt Microsoft ( because monopolies are bad & competition is good )

And no, my friend, PHP doesnt suck, but unfortunately many of its users do, as with anything thats popular.

Ben on May 21, 2008 08:18 AM

You may be missing the problem-space php is meant to address. That list of keywords isn't long, by any comparison. The function list is long, unless you think of the underscore as a namespace scope character, then it just feels like a normal library. Do you want to compare the list of php functions to the list of .NET methods? php is common because it doesn't generally screw around with overengineered object models, instead it tends to use handles. It's small and fast. It scales.

Because of this C sensibility that eschews much of the overwrought object casting, reflection, narrow-casting, boxing and unboxing, factory patterns, &c., it fits on thin middle (presentation) tiers.

I have to say, after the whiny, amateurish article about XML and the whiny, amateurish article on php, this site no longer holds any value for me. I haven't seen any aggressive stances on real problems for months. I'm outta here.

Brianary on May 21, 2008 08:21 AM

Python philosophy is about having a concise powerfull language, philosophy which has proven to be a good choice (As explained in code complete).

I still prefer PHP though it is a mess (non consistent function naming, useless once in a lifetime function proned to be unsufficiently eyeballed/tested).

Why do I prefer php ? Easy to use and powerful, with a low and high level control. 'Rail' like framework (Cake/symfony) are even being ported on PHP. So what is the problem with PHP ?

As a sysadmin however I am really scared of PHP because its community is flaming hardened PHP project though security is a major issue in php not only because of the language in itself but also because of bad habits among developpers PHP.

(interview of stephen esser on php security that is quite uneasing)
http://www.securityfocus.com/columnists/432/2

And as for any open source project, I do think the project has the value of its community, and its community in my opinions are a bunch of careless freaks that just stack up functionnalities without regards for the core of the language, especially security.
I know the claim of php6 on security, but the simple presence of the mail() function is unbelievable. Using this function is like asking to be spanked naked on the web.

I am still an happy php user but not very confident in its future.

jul on May 21, 2008 08:21 AM

I will agree that certain aspects of PHP suck, for instance having to use functions on arrays instead of seeing them as objects and using the array->function way of doing it.

But PHP fulfills it's purpose brilliantly. It's designed for the web, and I haven't found another web-based programming language that makes it as easy as PHP does. What requires one line in PHP can take at 6 to 10 lines and objects in say, Python (I know Python is used for things other than the web, but still).

For what it is designed for it works great.
Some complain about the $ and -> notation, but this just gives personality to the language.
Others have complained that there are so many different configuration possiblities, like magic quotes or register_globals, but any experienced PHP programmer knows how to either disable these, or completely code around them.

And Jeff, you've complained about the sheer number of functions in PHP. Now I'll agree that they could use namespacing, but that doesn't matter really. PHP's manual is the best and most comprehensive manual for any programming language I've ever seen, and you can quickly find a function and its parameters based on what you want. You cannot honestly tell me you jsut look at one giant alphabetic list of functions to try and find the one you want. If you are, then you are effectively nullifying your argument, as the developers have given you a great resource and you are just ignoring it.

And on the subject of script kiddies, I'll concede that there are far too many out there, and the code they write is atrocious. But the beauty of PHP is that it is simple enough for that to happen, but still incredibly powerful and powerful enough for experienced programmers to write clean, ordered and well-written code that goes like the clappers.

I think you're just nitpicking really, and PHP is a great tool to anyone who knows how to use it properly, despite some of it's flaws.

Matt Wilkinson on May 21, 2008 08:22 AM

Seriously, what's up with the stats on the TIOBE page?

According to the "Delta in position" column, PASCAL, COBOL and LUA (whatever the heck that is) are GROWING STRONGLY.

Meanwhile, C++ and JavaScript seem to be dropping in popularity.

How can that possibly make sense?

Rofa on May 21, 2008 08:23 AM

PHP itself isn't that bad really, the problem is that it easly allows people to write big ball of mud applications. However, you are always free to write good structured and clear applications. So the problem comes probably not from the language itself, but from the people, who use it.
That's probably why everybody always says PHP doesn't have OO. Yeah, it does! Just because people don't use, doesn't mean it's not there. I think it's very well possible to write good PHP application, just as long as they don't get too big, because web-scaling is a whole other issue.

Funny thing is, when someone ask around office, if there a PHP function to do task X, the answer is usally:

"PHP has a function for EVERYTHING!"

And it's true! Wether or not that's good, i don't now.

greg on May 21, 2008 08:28 AM

I've written about 200k lines of php in the last year. I've also written a huge amount of VB.NET and C# too. I find that the largest difference is that php will let you do what you want to, ugly or clean, whereas the others tend to guide you toward cleaner code. You can be clean with php, you're just not going to learn it from online tutorial sites. OO only really came with PHP5, so most of the stuff out there - even though 5 has been out awhile now - hasn't really been moved over. The frameworks are nice, and can really help, but often times it feels like you're just bring out a bigger sledge hammer.

Chris on May 21, 2008 08:35 AM

-------------------------------------------------------------------
Seriously, what's up with the stats on the TIOBE page?

According to the "Delta in position" column, PASCAL, COBOL and LUA (whatever the heck that is) are GROWING STRONGLY.

Meanwhile, C++ and JavaScript seem to be dropping in popularity.

How can that possibly make sense?
Rofa on May 21, 2008 08:23 AM
-------------------------------------------------------------------

I've heard COBOL is still used by the majority of banking systems and LUA is an upcoming scripting language used a lot in Games today (for example World of Warcraft and Civilisation 4).

greg on May 21, 2008 08:36 AM

"And does this also mean that HTML and SQL arent any good?"

Actually... it does! SQL is a curse for computer science, huge legacy of bad choices both from the semantic and the syntactic point of view. It would take me too many words to explain why SQL is a bad programming language.

HTML took forever to decide if it was a language to describe the structure of a document or its aspect, it's full of legacy tags that nobody uses nor knows what they were for. Add CSS and JS to the mix and you get something that nobody fully implements, nor understands.

E[X] on May 21, 2008 08:37 AM

Smells like a troll.

"If you sit down to program in PHP and have even an ounce of programming talent in your entire body, there's no possible way to draw any other conclusion. It's inescapable."

So the guys that coded all the popular websites you mentionned don't have an ounce of programming talent ?

You can make bad code with anything.

manu on May 21, 2008 08:40 AM

It lets people actually get the job done and for those who pay the bills that's what matters. While I like the concept of logical syntax and clean code, working code is what most other people expect. PHP seems to produce results for a lot of people.

Larry on May 21, 2008 08:40 AM

"What personally makes me laugh in my mind is how everyone always says how PHP is so badly designed etc., but never can actually show how it slows down their app development."

Huh