PHP Sucks, But It Doesn't Matter

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.

For platform independent web applications I believe that PHP is one of the better choices. It is in no way an elegant OO language even though OO has been introduced recently. The list of functions IS scary and have all sorts of problems as mentioned previously.

However, despite the lack of objects encompassing the built in methods it is very possible to design and code well thought out solutions. The language doesn’t FORCE you into good design, but it’s available for the taking.

I have no doubt the language will evolve to the point where good design is encouraged if not enforced, but for the moment - it seems to be one of the better options if the hardware/software platform is undefined.

Alright it’s like this…

I pay about 100 dollars a year total to host lots of web sites, most of which I coded in PHP because the WEB HOSTING FOR PHP IS CHEAP! And I’m cheap. And the hosting to do a ASP.NET site is expensive.

And to do down and dirty cheap stuff that doesn’t require a whole lot, it’s easy to mock it up in PHP. I think it just grows past that. Facebook was probably just mocked up in PHP and then it kept going because it was too hard to convert.

Long live the ghetto king of the web languages, PHP.

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.

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

“”"
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 QD 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.

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

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 …

If you want to create a community for developers, statements like the above, are the wrong way to go about it.

I’m just trying to be honest about my deep misgivings with the PHP language. It has some rather severe architectural problems, more so than any other language I can think of. Even my beloved, much-maligned BASIC.

Also: those statements are deliberately over the top. It’s supposed to be a little wry, a bit tongue in cheek. You know, humor?

That said, I absolutely think it’s important for PHP devs to be aware of the architectural limitations of PHP, and understand the alternatives. I’m not asking them to stop coding in PHP, just to have some context.

But as I said in the post – results are what matters!

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.

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.

@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.

I love PHP =(

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.

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.

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.

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.

@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.

@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.)

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.