Anti-PHP ammo

djberg96 on 2003-10-31T05:58:24

Someone on #python posted this. Not sure if it's been mentioned here before, but I don't think so. Interesting read on why PHP is a PITA once you reach the "large project" stage.


confirms what I already thought

TeeJay on 2003-10-31T09:40:41

I tried PHP briefly before applying for a job in PHP web shop.

They were really sold on it and just couldn't grasp why there would be any problems. Another PHP outfit I visited a few months ago used for for shell type scripting but PHP for their sites. They thought that perl would be too hard..

It does show that large software projects are hard and require decent programmers and a real language, not self-trained html 'programmers' and a toy language like PHP or ASP.

Solid Article

chromatic on 2003-10-31T17:21:45

I'm currently rewriting a PHP application in Perl at work. Magically appearing variables and lack of namespaces have been getting on my nerves, too.

PHP is good for some tasks

jjohn on 2003-10-31T23:14:04

Although you may only be able to pry Perl from my cold, dead hands, I've found PHP suitable for smaller apps. I'm currently writing a PHP front end for XML-RPC server. Although I think PHP leaves much to be desired, it's far from the worst web programming system I've used. That honor goes to the Lovecraftian horror know as ASP/VBScript.

As long as strictly front-end display tasks are deligated to PHP, it's a fine system. It's when users try to encode crazy business logic in PHP that teh suck begins. Give PHP a try. You'll laugh at doing string comparisons like this :

<?php
   if (strcmp(foo, "jjohn") == 0) {
      echo "Yeah man!"
   }
?>

PHP is a dynamic language that uses clumsy C mechanism for string handling. Bizaare.

In short, I would be happy to work with PHP again for small, GUI things. However, PHP is quite easy to abuse. It's even more poorly suited for larger projects that (critics of Perl claim) Perl is.

Re:PHP is good for some tasks

trachtenberga on 2003-11-01T07:18:24

And why wouldn't you just do: if ("jjohn" == $foo) ? There's no need for strcmp(). If you're really a regex guy, you could always do: preg_match('/jjohn/', $foo).

Scoping

bart on 2003-11-01T02:06:37

I must say, I find it a pretty good article, but I disagree on the author's point of view on variable scoping — in addition, he seems to have overlooked a few extremely bad traps.
  • As opposed to the author, I do like automatic limiting of the scope of variables to the sub (er, "function") they are in. By contrast to perl, everything that you use is a local variable, unless you explicitely say it isn't. I think that's a good thing.
  • OTOH, I hate it that every variable you create outside of a function, is a global variable. There's no way you can lexically limit the scope of a variable to a block or library file. Everything is visible from everywhere.
  • Furthermore, there's no namespaces (no "packages", in Perl terms), so global name clashes are something to be very wary of.
  • And finally: the autoglobal feature can allow the user, through clever use of CGI parameters on the browser's URL, step on any one of them, making the script behave in all sorts of unintended ways, unless the programmer explicitely clears them.

Re:Scoping

trachtenberga on 2003-11-01T07:40:01

The piece does a good job of showing you ways the you can shoot yourself in the foot while using PHP, but I really think many of these problem can be avoided in any professional development context.

By "professional development context," I mean you are running your own machine and server and aren't on a shared host. On your own box, you have control over all the settings and can make sure all the troublesome ones are turned off, the good ones are enabled, etc. Whether PHP should allow you to use "stupid" settings is a different issue, of course, but PHP tries hard to make things easy for non-programmers and it's hard to balance these two sides.

I agree the lack of consistency in function names is nothing to be proud of, but new functions are being named consistently. Again, whether it's worth it to break existing code to enforce naming standards, is a tough question. Personally, I wish PHP 5 would rename everything the "right" way and provide some backwards compatable aliases, but I doubt that'll happen.

However, the array example is contrived and stupid. If you were to do something like that (and when would that be?), you'd probably just iterate over it using foreach(), so who cares what the internal order is? Perl hashes don't guarantee any order, but I don't see the sky falling down.

I find that I solve the issue of namespaces by creating objects and holding all my "package" variables as instance variables. Therefore, you only end up with a few major objects floating around in the global namespace and whatever "local" variables you're using in your script.

Re:Scoping

trachtenberga on 2003-11-01T07:41:37

Shit. I really should have hit preview so I wouldn't have lost my paragraphs. Sorry about that.