PHP, Are you serious?

A long time ago, in a galaxy far, far away, I programmed in PHP for a mortgage company. I ended up leaving that job for personal reasons. Apparently, 40 hours/week truly is not enough. I was a perl programmer prior to that excursion, and I guess I never grew out of it. I always felt uncomfortable there. For a while I thought it might be social, but after further reflection, it’s obvious it was actually PHP’s fault.

To frame this, I just got back from YAPC::NA. I learned all kinds of new techniques and tricks from MJD, chromatic, brian d. foy, Randal Schwartz, Damian Conway, and countless other acquaintances. What’s not to love about Mason, DBIx::Class, and the brain bending functional tricks you can learn from MJD and chromatic? I never knew that @INC could contain a subroutine reference, did you? I also never thought of something so clever as recursively calling an anonymous sub ref contained in a scalar by using another anonymous subroutine that dereferences that ref at runtime.

So now, after refactoring a TON of my code to Perl Best Practices, I’m back into the land of PHP temporarily. Our administration group at work is looking for a project tracking system. After favorable experiences with dotProject a year ago, I suggested that. I hadn’t touched dotProject or PHP since dotProject’s 1.x branch. They’re now at 2.0.4 and it seems there just might be a few more hands in the pot. The code is not as coherent and refreshing as I remember it.

I’ve been spending time building a module for additional “fund” tracking. PHP seriously gets in my way. Granted, I have a very heavy bias against anything but perl, but my god, there’s a reason why this Google Search exists. They’re not lying. I’m dealing with PHP4, so perhaps PHP5 has gotten better, but I harbor serious doubt that even by getting “better” that PHP5 would approach anything a serious computer scientist / programmer would consider usable.

The language is a patchwork of functions. There’s no real defining factor or consistency. As a matter of fact, the only thing consistent is the fact that regardless of what library in PHP you’re using, chances are the function names and argument orders lack consistency in that module and in the whole picture.

Don’t get me wrong, PHP is great for web designers and novices. There’s a very low barrier to entry. However, we now have a landscape littered with horrible PHP applications that expose servers to vicious attacks from outsiders. PHP is not by any means a language that should be taken seriously by any serious developer. Please invest your time elsewhere. I’d even recommend Python over PHP. Ruby would be a more worthwhile excursion.

PHP makes simple things simple and hard and obscure. Hard things are impossible. The biggest hole in the language from the perspective of a Perl or Lisp programmer is the complete lack of lexical scope. I know, inside of a function there’s a lexical scope, but it’s not really a lexical scope, it’s a hack. You have your choice between global scoped variables, or variables scoped inside of a function. No other closure provides an effective measure to force destruction and garbage clean up. More importantly, certain techniques become ridiculous without proper lexical scope.

Early version of PHP3, maybe even “late” versions, had no scoping even for functions. This became a problem to anyone used to using recursion to solve recursive problems. Recursion relies on the fact that each call to the function can resolve independantly of the rest of the call stack. Modifying variables that are still in wait on the stack can cause some “unexpected” behavior.

There also seems to be a problem with ternary operators. Unexplainably, if the false condition of a ternary construct is in itself another ternary, the false is evaluated. In order to “nest” ternary operators, you need to enclose each INDIVIDUAL ternary in its own set of parentheses. Find precident for that illogical BS. Why in the hell are we evaluating the false condition if the current ternary operator has returned “true” ?

It’s been a painful process, but in order to program in PHP, I’ve learned that you absolutely need a function reference. It is impossible for a human being to formulate a logical function naming convention (is it “noun then verb? verb than noun? do I separate with underscores, or just smash it together”?) let alone the argument order even inside the same “module”. Just peruse the function reference on the php.net site to see what I’m talking about. Zero consistency. Please, pick an interface and stick with it.

Bottom line, PHP is a good place to start, but don’t stop there. Pick up another language. I recommend perl. I’ll even teach you. I’m gonna be teaching at NIH in the near future and I’ll be sharing my course material here.

Comments 2

  1. mglibresdwebsite.com wrote:

    You’re article sucks.

    mglibres@dwebsite.com

    Posted 08 Sep 2008 at 12:22 am
  2. brad wrote:

    mglibers: Insightful and informative comment.

    Things have changed a lot with PHP since I wrote this article, so it’s entirely possible some or all of the issues I addressed have been fixed. However, considering a number of shake-ups in the PHP community of late, I doubt PHP is completely out of the tunnel.

    Posted 08 Sep 2008 at 4:02 pm

Post a Comment

Your email is never published nor shared.