top | item 2463305

Why PHP Was a Ghetto

157 points| vlucas | 15 years ago |codefury.net | reply

164 comments

order
[+] hapless|15 years ago|reply
"5. Arguably the best documentation for any language"

I should very much like to see that argument.

My impression of PHP documentation (after using it for three of the last five years) is that it's a endless pile of bullshit whose primary content is in user comments on the doc pages.

That's the core library. Third party libraries are typically wholly uncommented and undocumented.

[+] ch0wn|15 years ago|reply
I came to say that. Even without comparison it should be very obvious that the PHP documentation is incomplete and badly written. The user comments can't make up for that, especially since there is no quality control for them.

The python documentation is an example of good documentation. And again, it's tied to the language's culture, where documentation has a really high priority.

[+] tremendo|15 years ago|reply
PHP's docs are good and bad in the same way that PHP itself is good and bad. For PHP the language reference is quick, easy, simple. Offers the syntax with required and optional parameters followed by a quick and typical use case. When that isn't sufficient, the comments may or may not have the exact use case you're looking for, many times they do. So it's all very convenient for drive-by-programming, like PHP. Good at quick'n'dirty, not so great for more involved, or for more carefully thought out solutions.
[+] slig|15 years ago|reply
It's more like "Arguably the most used documentation for any language." As it's impossible to memorize the patternless names and random parameter order for similar functions.
[+] nsfmc|15 years ago|reply
I think the other thing that's missing here is that there's nearly often a conflict between the actual behavior of a function and the overly optimistic documentation which is then amended by a series of caveats.

I think i could forgive php more for behaving (and being named & structured) wildly inconsistently were it not that the documentation tries to make up for this by pretending this is actually not the case.

So not only do you have this issue where the behavior of a function may be erratic but the documentation attempts to gloss over the issue by describing a function's most optimistic outcome rather than its actual behavior. Any behavioral caveats are left in the Notes section which in any other language documentation is reserved for "not thread safe" or "uses an easily guessable seed" or "execution blocks network access". Instead the Notes are used to explain "optional arguments not included change the behavior of this method to behave like this other one, but give no warning or otherwise visible indication of error."

The whole "php is defensive programming" statement holds because you can't trust the documentation to be upfront about inconsistent behavior.

[+] andjones|15 years ago|reply
The accessibility of PHP is its strength and downfall.

There exist so many third party libraries because of the low barrier to entry. But as more people join the party, the party moves toward the average. The average third party library is an untested and undocumented mess. I do not think this is specific to PHP.

[+] akavlie|15 years ago|reply
Agreed, I find it's often very sparse myself. Compare to the Python standard library docs, which tend to be much more thorough.
[+] config_yml|15 years ago|reply
>> My impression of PHP documentation (after using it for three of the last five years) is that it's a endless pile of bullshit whose primary content is in user comments on the doc pages.

Agreed, but the user comments include a huge collection of common problems and their (mostly) quick n dirty solutions. This is a part of what's making the language so accessible for newcomers. Of course it doesn't necessarily encourage best practices.

[+] mkramlich|15 years ago|reply
> that it's a endless pile of bullshit whose primary content is in user comments on the doc pages.

I noticed that too, and it floored me.

[+] sigzero|15 years ago|reply
Indeed. Python's is better and certainly Perl's is better.
[+] jamesgeck0|15 years ago|reply
The docbook source for the core library is actually available in a sort of online wiki editor thing, so in theory anyone can improve it. Unfortunately, I've forgotten the URL and I can't find it via Google.
[+] georgieporgie|15 years ago|reply
While I think you're being a bit harsh, I think you raise a good point. Admittedly, I haven't done significant PHP development since PHP4, but my recollection of the documentation was that it was mediocre, and that all of the really good information was in the community comments.
[+] rickmb|15 years ago|reply
PHP has now split into different factions. Those like the WordPress community, who still party like it's 1999, and those around the major frameworks, libraries and testing and QA tools, who've taken their cues from Django, Rails and such.

The two have so very little in common they might as well be using different languages.

I'm oversimplifying of course. There are a number of large an quite successful communities that fall somewhere in between, like Drupal. The point is, neither the communities nor the code they write have much in common other than having PHP somewhere deep at the core. There is no "this is what PHP is like" anymore, and that hasn't been the case for over half a decade.

[+] te_chris|15 years ago|reply
You're completely right. I'm an OO php developer (among other things) and when I go back and work on something like WP or Drupal it's just so foreign, despite being the same language. I can see how and why people like those systems, but as a developer they're just so difficult. When I do client cms work I use SilverStripe and it's great because they've built on top of a rails-esque php5 MVC framework so it just feels like programming any other php5 mvc app but with CMS stuff.

A couple of asides as well, sapphire, SilverStripes framework has now been spun off as it's own, independent php5 framework https://github.com/silverstripe/sapphire. Secondly, his mention of CodeIgniter got me curious again, great to see they've finally dropped php4 support. I'm going to have to check it out again I think.

[+] edw|15 years ago|reply
A lot of my designer friends love Drupal, and they wonder why the veins in my neck and forehead start to bulge when they mention it. They love it because it allows them do things that they never could have imagined, whereas I despise it because it does badly what any competent Django or ROR developer could do in more quickly and maintainably. (Yes, I know, there's a Drupal module that solves that problem…)

I mention Drupal because I find its "the node is our hammer and all solutions are nails, er content management systems" approach to doing things is a perfect example of the PHP google-then-copy-and-paste programming caricature that is all too often true.

But the author's correct: to the extent that PHP sucks, it sucks not because of PHP itself but the culture that surrounds it. In my experience, everyone's a noob, an advanced noob that is eager to share their bad habits, or callused actual experts who assume that you are one of the aforementioned noobs and assume you have the cognitive capacity of an overripe banana.

I know several PHP developers who I respect—Hi, Sunny and Tom!—but they seem to exist outside the PHP space-time continuum.

[+] dasil003|15 years ago|reply
I actually think the Drupal architecture and codebase is amazing for what it is. There is a huge class of middle-tier clients that want a ton of functionality which can only be provided by a prepackaged modular system like Drupal, and the amount of extensibility Drupal affords you is impressive.

I don't ever want to touch Drupal again, but not because the code sucks. I just think it's working at the wrong level of abstraction. I understand the need for that level of abstraction, but personally as a UX designer and developer I feel the compromises Drupal forces cheapen my work.

[+] dasil003|15 years ago|reply
I left PHP in 2005 because it felt like I wasn't learning anything anymore. At the time I thought it was the warts, but in retrospect it's definitely the community. The problem is that every good piece of open source PHP is drowned out by a hundred shitty spaghetti projects.

When I picked up Rails, everything clicked right away because it directly addressed so many of the shortcomings of how things were done in PHP. Digging deeper in the Ruby community I found a genuine passion for pulling in great ideas and advancing the state of the art. Ruby has shitty projects too, but the good stuff is more prominent and easier to find.

After 5 years with Ruby I'm not particularly eager to leave, but I do feel the urge to pick up another language to expand my horizons once more. Preferably something with a high density of good ideas, like Haskell.

I know PHP has evolved and is quite capable as a language, but the only way I would touch it again is if I was working on a project that was interesting for bigger reasons (eg. Facebook).

[+] there|15 years ago|reply
Rasmus generally promotes abstention from using frameworks, and the use of PHP as more of a templating language.

from watching a recent talk (http://ontwik.com/php/php-performance-by-rasmus-lerdorf/) he gave, i didn't get the impression that he hated frameworks, but more that he hated most php frameworks because they were slow.

in the video he says a big problem with current frameworks is that they deploy to production the same code used in development, which still includes all of the knobs and extra includes that have to be pulled in on every request to support things that aren't used. he would rather see frameworks turn code into a streamlined bundle of code that gets pushed to production.

[+] bkudria|15 years ago|reply
That's be much easier if there were some decent reflection and metaprogramming support in the language.
[+] runevault|15 years ago|reply
I find it amusing how hyper-specific he gets in the comments defending PHPs speed, saying comparing it to even Python is unfair because it bytecode compiles to save time.

To me, that sounds more like a flaw in PHP that it doesn't save bytecode and reuse that if the underlying source has not changed, not a defensible reason to claim it is faster than other "similar" languages.

[+] compay|15 years ago|reply
I posted some generally supportive comments on his post, but dared to point out that PHP's interpreter is in fact rather slow compared to pretty much everything else, so he shouldn't claim that PHP has "maybe the best speed and scalability among script-based languages." I ended up getting attacked as some kind of PHP hater.

If PHP has a reputation as a ghetto, it's in part because of cocksure noobs like this who think they know everything and are impossible to have a rational conversation with.

[+] roel_v|15 years ago|reply
But what are you comparing, the interpreter or run speed of bytecode? I haven't seen any comparisons between languages for several years, but PHP used to be fast for its class, and I can't think of many reasons myself of why that would've changed (doesn't mean it hasn't, but I'd like to see some evidence).
[+] katzgrau|15 years ago|reply
I am said "cocksure noob."

If you disagree with @compay, you will assuredly earn the same title.

[+] jallmann|15 years ago|reply
CodeIgniter is really not that nice. Maybe it seems cool for the uninitiated, but it is just a PHP clone of Rails. CI and kin can't hold a candle because the expressive power of Rails doesn't come from the framework itself, but from Ruby.

There are a few times when the choice between one language over another is more of a pragmatic issue rather than one of taste, and Ruby's ease in creating DSLs (and hence, Rails) is a perfect example.

As TFA mentioned, Ramsus Lerdorf has the right idea. PHP is a templating language. Contorting it into a general purpose language and squeezing a Web framework out of that is unpleasant when there are so many nicer alternatives available. I almost feel bad for Rasmus; people are using his language, taking it beyond its intended scope, and giving it a bad name for that.

[+] Egregore|15 years ago|reply
PHP is popular because of low barrier to deploy. All hosting providers offer PHP, while with other technologies you'll have to shop a little.
[+] chc|15 years ago|reply
Besides its ubiquity, it is also the only real contender that is specifically designed for the Web. You can just stick a PHP file containing `echo "1 + 1 is " . (1 + 1);` anywhere on your site and it will tell you 1 + 1 is 2. Ruby scripts (for example) can run that way, in practice a server will be set up to use a Rack interface instead of just echoing the output of a Ruby or ERb file. This simplicity is attractive to many who are just starting out.
[+] kprobst|15 years ago|reply
PHP + MySQL ended up being the VB+Access of the FOSS ecosystem.
[+] kertap|15 years ago|reply
This is very true.

Also it's worth noting that if you do want to do PHP "right" and use a framework like Zend or Cake you will probably still be shopping around a bit because you're not going to get the ability to use those frameworks out of the box on most hosting providers.

[+] andjones|15 years ago|reply
The fact that many PHP projects end up in unmaintainable spaghetti code is a mark against the programmer and not the language.

Take your average PHP programmer and force him/her to code in Ruby and the same mess will result.

The fact that PHP has so many "noob" programmer is indicative of its success in creating so many great projects and websites. We have made PHP so easy that even your grandmother can do it.

From the article:

If you are capable of making wise software design decisions, PHP is a great choice to build your web application with.

[+] damncabbage|15 years ago|reply
> We have made PHP so easy that even your grandmother can do it.

I'd wager it's so easy that even your grandmother can do it /badly/, while putting her business or data at risk.

More seriously:

Frameworks or languages that make it easy to be secure by default are a lot better, both for newbies who don't know better, or for old hands who slip up once or twice.

The simplest example I can think of to illustrate the difference:

    <h1>Hi, <?php echo $name; ?></h1>

    vs

    <h1><%= name %></h1>
(Say "name" is "<script src=xss.js></script>". The former is vulnerable, the latter is not. Both are just as easy to write.)
[+] hackernewz|15 years ago|reply
ZF and CI are horrible examples of coding practices. They are extreme examples of "make a class for everything because you can". ZF file and directory structure is at odds with PHP 6's namespaces, in fact it will probably have to be completely thrown away to make way for a ZF 2.

CI doesn't even have the base class of any "controller" defined anywhere for you to read. It is created on the fly every request. This guy is a noob and doesn't understand what good programming is.

[+] nickik|15 years ago|reply
the bad:

>Ugly syntax

The syntax is not that importent (the semantics are the BIG problem) but you are right. What to expect from somebody that didn't even want to read a hole parser book (not blaming him i think there boring too but if you don't want to read a parser book implment a lisp)

>Lack of some necessary features that other languages have (prior to 5.3, namespacing, closures)

Having a feature in the language is good but not worth a lot if there not idiomatic to use.

>Inconsistent function naming, usage, and other quirks Inconsistency is te big word. Everywhere. Nobody thought about what is done how, where or why.

>The fact that 80-90% of PHP projects are probably gigantic piles of shit

yeah.

The "good":

> Standards (not universal, but generally a flavor of MVC for most projects, and little procedural crap)

1. Application Design is more then just MVC. 2. Most PHP Code produced still suckes. Sure there are frameworks and standards know but how many % of the people writing php know this? I know lots of people how get tough php just like 10 years ago and if they are not really into programming (like people here) the will never learn the good stuff.

Having "Standards" and people using them is a diffrence.

>A very low barrier to entry True. Php was just at the right place at the right time.

> Speed & Scalability (maybe the best among script-based languages)

From most benchmarks I have seen php was really slow. Isnt it compiling to bytecode witch then gets inerpreted?

There are projects like HipHop and phc but I havn't seen really good numbers for them.

Are there good up-to-date benchmarks to support this?

> A great unit testing framework

What language that could has somewhat the same scope as php does not have really good testing frameworks?

> Arguably the best documentation for any language

Read some compents in this thread to see peoples opinions on that.

[+] Staydecent|15 years ago|reply
I agree with the post, and have come to hate PHP less. But the main reason I choose python or ruby (when I have the choice) is because of the syntax. I'm not sure the proper term, but I find you have to write more characters, as apposed to ruby or python, to say the same thing.
[+] EGreg|15 years ago|reply
There is a reason why facebook used PHP, wordpress is in PHP, and a lot of other tools are also. PHP is popular, it's easy to find developers who will write it in it, and it's also easy to find PHP hosting for noobs. When there is a popular platform, you will get lots of apps written on it.

That said, the high art of PHP was always to make really performant apps while having your code as organized as possible. These days, this is being done very well with files, autoloading, and opcode caching. If you do things this way, Rasmus would be happy, and things would be fast.

I am a PHP developer. A lot of what I saw in the past few years was frameworks like Cake and symfony that basically copied Rails or brought some heavy techniques with a lot of overhead. This is not the PHP way. If you want to see a framework that does things in a more PHP way, I would humbly submit my own:

http://phponpie.com

It's open source. It's called PHP On Pie for a reason: because it's easy and it uses real PHP techniques, not tries to emulate Ruby or Python. PHP has its own beauty, such as arrays which can support numeric and string indexes at the same time.

All this said, these days PHP is outdated for large sites. Not because there is a lot of crap written in it -- which I agree with. But because it still works only synchronously, and the culture is too server-heavy. Large sites should be written like this:

  Clients (browser, etc.) do most of the interface logic.

  Components should render themselves using javascript, and only use the server for data

  Server does web services (REST, socket push, etc.)

  Server should not have to do things synchronously.
Node.js rocks in this respect. Unlike PHP, I can literally issue 10 independent queries to 10 different databases and combine the results as they come in. In PHP, I would have to issue this stuff sequentially. That's slow.

The second thing in PHP is fixable. People should move most of the logic (that doesn't need authentication) to the client side, and then write all their web services in a very simple way. Stop generating all your HTML on the server. Check out

http://weblog.rubyonrails.org/2011/4/18/why-http-streaming

and

http://www.facebook.com/notes/facebook-engineering/bigpipe-p...

[+] aphyr|15 years ago|reply
PHP has its own beauty, such as arrays which can support numeric and string indexes at the same time.

Rarely do I actually spit on my keyboard.

Not only do most other languages do associative arrays properly, so, you know, numeric and string indices don't clobber each other, but they also don't explode when indexed with, say, anything but decimal literals. You seriously think this is beautiful behavior?

http://aphyr.com/journals/show/fun-with-php-arrays

[+] mccutchen|15 years ago|reply
> PHP has its own beauty, such as arrays which can support numeric and string indexes at the same time.

What's the difference between PHP's arrays and hashtables/dictionaries/etc in languages like Python, Ruby, and JavaScript?

As a Python programmer (who started with PHP years ago), PHP's arrays now seem sort of muddled or confusing. I prefer Python's dedicated list/dict types (though nothing is stopping you from mixing numeric and string keys in a dict).

[+] sigzero|15 years ago|reply
He uses "was" like it still isn't.
[+] kouiskas|15 years ago|reply
Average developers blame the language for their inability to make the best use of it. Good developers are too busy writing great code with the tools they have at hand to care.

Some languages have strengths for particular applications, but spaghetti can be written in anything.

And why should you care if 99% of the rest of the world writes shit code with the language you use, as long as your own house is clean?

[+] MatthewPhillips|15 years ago|reply
The author points to the recently good support for frameworks (specifically MVC), but hasn't there been a bit of a backlash against overly opinionated frameworks and a move to more lightweight frameworks like Sinatra? Isn't PHP going to just be behind on this trend as well?
[+] nuclear_eclipse|15 years ago|reply
CodeIgniter, which is what the author recommends and I have used extensively, is already a very lightweight framework, or at least compared to some of the very opinionated ones like Zend. CI goes out of its way to make sure you can use or ignore as much of the framework as you want, with the exception of its core controller and routes system.

Components like templating, views, active record, form validation, etc, are completely optional, and it's trivial to replace or extend components without having to mess around with any of the core code. Just don't load that component, and use something else instead.

[+] trustfundbaby|15 years ago|reply
hasn't there been a bit of a backlash against overly opinionated frameworks and a move to more lightweight frameworks like Sinatra

--------------------------

Not to my knowledge ... there has been a rise in said lightweight frameworks, but thats just because heavy Frameworks like rails don't work for every scenario

[+] krobertson|15 years ago|reply
"In it’s pizza-faced adolescent years (pre-5.0)"

Really? It took 5 major releases and 9 years?

Ruby and Python have been around as long or longer, but seemed to get the language basics/semantics down earlier. They also grew a lot slower compared to PHP.