PHP Sucks, But It Doesn't Matter

May 20, 2008

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 Holmstrm:

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!

Posted by Jeff Atwood
407 Comments

I know I am WAY late to this party, but I have been searching for years to try and find the words to explain why PHP is bad. The fact that pretty much any site that's worth it's salt is built on PHP does not help the argument.

This is a perfectly stated concise summary of the PHP dilemma - or lack thereof.

As a developer though, I would write Python any day before I started building with PHP.

Thomas Burke Holland on April 13, 2010 11:25 AM

PHP absolutely sucks. It is irregular and inconsistent.

Yes, you can write bad code in any language but PHP is the only mainstream language where it is very difficult to write good code.

PHP was develop by amateurs for amateurs.

Its performance is terrible. There is a reason that Facebook needs about 1 server per 200 active users.

Beavis on June 25, 2010 10:25 AM

"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?"

LOL

Java is a clunky language, its only positive are its libraries and the JVM. Luckily you can use the JVM

Spring and Hibernate have not been ported to other langauges. Those things absolutely suck.

If you want a visual demonstration of the clunkiness of Java compare ActiveObjects to ActiveRecord.

Beavis on June 25, 2010 10:27 AM

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

Only if you consider security and maintainability irrelevant.

I have yet to meet a professional programmer that uses PHP.

And by professional, I mean a programmer that actually is a programmer. Not a self-trained API monkey.

Beavis on June 25, 2010 10:30 AM

One more "php-really-sucks" example: Just try to "catch" a specific error... Surprise! PHP core-functions cannot raise catchable exceptions! PHP is so yesterday...

PS: No, I don't write my own error-handler which could raise exceptions for errors.

PPS: Its really interesting to see, that in the php-world nerly nothing improves (Zend == strange unknown company; ZF == crappy toolstack, no framework; PHP5.x == crappy/buggy; PHP6.x == gets_never_released;)


PPPS: try ruby! ;)

Fpauser on December 3, 2010 4:21 AM

Wow, I think I walked into a RELIGIOUS ISSUE™ here.

I am a Pythonista since 1999, and only now am beginning to learn php as the firm we are doing work for is a php house. OK, so I learn php. It sure is different from Python! Still, I think I like it, even if it, like pearl, has a bazillion ways to get things done, none of which is designed according to a plan, and none of which is in any way the clear obvious way to get things done. But it works, it's IN the web page, I can do normal html and such, and switch into and out of the language without establishing special frameworks, so this looks like it's handy and useful. But it sure could use a rewrite to make it systematic.

I like it. I also look sidelong at it, whilst going HUH?!?

KBailey on December 4, 2010 2:36 PM

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

Bjarne Stroupstrup, while a smart guy,should not be quoted when he is just trying to excuse the crap design of C++.

Yes, C++ is better than PHP and Bjarne is far more educated then the amateurs that developed PHP, but that quote proves nothing and does not excuse the crap design of PHP.

It's like quoting "The business of America is business." to show that it is okay to let business run America even though Coolidge was owned by big business.

I have never met an actual professional programmer, with a solid computer science education, that even considers using PHP.

I have also never seen a piece of PHP that wasn't a terrible mess, including and especially WordPress, Joomla, MediaWiki, etc.

Beavis on July 7, 2011 3:34 PM

«Back

The comments to this entry are closed.