WEReveal

Get with the Program!

Ok, I need to rant a bit here to get this off my chest. Sorry if some bricks I throw come your  way, you can pick them up and throw them back if you like. In the past week I have worked with two different clients which are still maintaining old PHP code, one that goes back as far as PHP version 3. There is a time when it gets more costly to maintain old code than it is to update it to the new. I believe that time is now. STOP USING PHP VERSIONS EARLIER THAN 5.x  Oh, that felt good.

I believe that it is certainly time for PHP coders to abandon writing any new PHP code that isn’t 100% compliant with PHP 5, especially stop writting PHP 4 OOP code. It is my personal feeling that some of the current code being produced to be “backwards compatible” with PHP 4 is really lazy coders not wanting to really learn how to do OOP correctly. There is no reason to write “backwards compatible” code anymore. Good grief! I have a book published by O’Reilly in 2004 titled “Upgrading to PHP 5” – thats 4 years ago – an eternity when it comes to technology.

I would be radical enough to say that the PEAR libraries maintainers should be given a date/time after which if the code is not 100% PHP 5, it gets dropped from the repository. Maybe they have set a time, I just haven’t seen it. I do know that all new code must be PHP 5 and for that I applaud them. Unfortunately, there is still a lot of old psuedo-OOP code in the PEAR libraries.

Ironically, I find some of the really old code written for PHP 3 doesn’t drive me as crazy as the PHP 4 OOP code does. Maybe that is because I think that PHP 4 only was capable of psuedo-OOP and even then, poorly. Also, as was evidenced this week with my one client, at some point PHP 3 code just stops working and is forced to be updated. On the other hand, many people are clinging to their PHP 4 servers and their PHP 4 code simply because they think it cost too much to upgrade (and in some cases, just too lazy).

I also have to laugh at some of the pseudo-OOP code I see done in version 4. Recently I saw a class that consisted of several var definitions, a constructor method and a single accessor method. The constructor method was most likely some pre-existing procedural code that was wrapped in its new OOP clothing and the vars given the $this-> treatment. The accessor method was there to get the value of the results of the constructor method. Another class in the same library of code was a bunch of loosely tied functions that didn’t interact with each other or act technically upon the class object. Rather, they acted upon data fed into them and spit it out, e.g. $results = $obj->cube(4). Both done in the name of doing OOP. Ok, both could have been done in PHP 5 too I suppose but I blame PHP 4 for that idiocy.

I believe the cost to maintain the old is going to become increasingly more expensive. Upgrading to the new could reduce cost in the end.

  1. PHP 4 psuedo-OOP does not provide all the advantages of OOP and so takes away from time/cost saving capabilities that PHP 5 has when adding to or modifying the existing code.
  2. PHP 4 does not have all the refinements of PHP 5 language requiring more code to do the same amount of work. PDO, XML, iterators, and error handling are all examples of time/cost benefits that PHP 5 has.
  3. Although PHP 4.4.x in general is much more secure than its predecesors, I feel more secure with PHP 5 although I would really like to see some of the depreciated globals etc just be dropped (and believe some will be in PHP 6). By following the PHP 5 way of doing things and abandoning the depreciated stuff should result in better code.
  4. Eventually, the code is going to have to be upgraded or replaced. PHP 4 is no longer supported. PHP 6 will be out soon enough. Upgrading now will provide the cost savings earlier than later. Upgrading later may end up costing you more since those that can convert your old code to modern may very well charge more. Also, any changes from 5 to 6 will certainly be easier than 4 to 6 although some I know are holding out till 6 comes out before converting. They believe they will have only one upgrade/replacement to go through. I suppose this may be true but seems to me, using 5 now will give a more gradual slope than going from 4 to 6.

Leave a Reply