After working with PHP 5 for quite some time now, I’ve had to go back to PHP 4 to develop a CMS for a client’s site where we don’t have much over the hosting environment. Going back to the old version has annoyed me quite a few times already and it’s probably made worse by the fact that I never really did much PHP 4 anyway (I’m quite new to the language, even though I have been programming in it on and off for 2 years) and lately I’ve been working in a combination of PHP 5 and C# (as well as various others) and generally being a bit more object oriented about everything.
First off there’s the whole not really object orientedness of PHP 4. PHP 5 isn’t that object oriented, but PHP 4 is miles off. Passing variables by value instead of reference unless you put stupid & symbols everywhere… whose idea was that? Also it’s obviously a bit hacked together behind the scenes, as exemplified by the fact you can’t do things like $this->getThing()->getOtherThing() without it barfing. Instead you have to put the returned value from the first thing into a variable and then call the next method… not a good sign in an interpreter.
You can just about force yourself not to access member variables of objects directly, even if you can’t set things to be protected or private, and make get() and set() methods everywhere, but sometimes it’s really useful to put things into static classes. Database routines would be really useful, for example. Instead I’ve taken to creating a great big global variable to hold an object and refer to it everywhere and use the member variables of that object to store other useful objects. At least methods can be called statically, but without static member variables they’re not as much use. (I use a similar technique when programming in Lingo to save having to reference all my globals in each script: store them as properties of another object that keeps state for the whole application.)
And very little XML support either… Even ASP could handle XML well, and even XSL, four or five years ago, and ASP as we all know is the lowest form of programming language ever invented. (Okay, there are worse languages than VBScript, but not many that site behind so many important web sites. I once worked on a half million pound project that was built in ASP… Scary!)
One thought on “PHP 4 annoyances ( = rant)”
i love you