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 dif­fer­ent clients which are still main­tain­ing old PHP code, one that goes back as far as PHP ver­sion 3. There is a time when it gets more costly to main­tain 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 cer­tainly time for PHP coders to aban­don writ­ing any new PHP code that isn’t 100% com­pli­ant with PHP 5, espe­cially stop writ­ting PHP 4 OOP code. It is my per­sonal feel­ing that some of the cur­rent code being pro­duced to be “back­wards com­pat­i­ble” with PHP 4 is really lazy coders not want­ing to really learn how to do OOP cor­rectly. There is no rea­son to write “back­wards com­pat­i­ble” code any­more. Good grief! I have a book pub­lished by O’Reilly in 2004 titled “Upgrading to PHP 5″ — thats 4 years ago — an eter­nity when it comes to technology.

I would be rad­i­cal enough to say that the PEAR libraries main­tain­ers should be given a date/time after which if the code is not 100% PHP 5, it gets dropped from the repos­i­tory. 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 writ­ten 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 capa­ble of psuedo-OOP and even then, poorly. Also, as was evi­denced this week with my one client, at some point PHP 3 code just stops work­ing and is forced to be updated. On the other hand, many peo­ple are cling­ing to their PHP 4 servers and their PHP 4 code sim­ply 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 ver­sion 4. Recently I saw a class that con­sisted of sev­eral var def­i­n­i­tions, a con­struc­tor method and a sin­gle acces­sor method. The con­struc­tor method was most likely some pre-existing pro­ce­dural code that was wrapped in its new OOP cloth­ing and the vars given the $this-> treat­ment. The acces­sor method was there to get the value of the results of the con­struc­tor method. Another class in the same library of code was a bunch of loosely tied func­tions that didn’t inter­act with each other or act tech­ni­cally 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 sup­pose but I blame PHP 4 for that idiocy.

I believe the cost to main­tain the old is going to become increas­ingly more expen­sive. Upgrading to the new could reduce cost in the end.

  1. PHP 4 psuedo-OOP does not pro­vide all the advan­tages of OOP and so takes away from time/cost sav­ing capa­bil­i­ties that PHP 5 has when adding to or mod­i­fy­ing the exist­ing code.
  2. PHP 4 does not have all the refine­ments of PHP 5 lan­guage requir­ing more code to do the same amount of work. PDO, XML, iter­a­tors, and error han­dling are all exam­ples of time/cost ben­e­fits that PHP 5 has.
  3. Although PHP 4.4.x in gen­eral is much more secure than its pre­de­ce­sors, I feel more secure with PHP 5 although I would really like to see some of the depre­ci­ated glob­als etc just be dropped (and believe some will be in PHP 6). By fol­low­ing the PHP 5 way of doing things and aban­don­ing the depre­ci­ated stuff should result in bet­ter code.
  4. Eventually, the code is going to have to be upgraded or replaced. PHP 4 is no longer sup­ported. PHP 6 will be out soon enough. Upgrading now will pro­vide the cost sav­ings ear­lier than later. Upgrading later may end up cost­ing you more since those that can con­vert your old code to mod­ern may very well charge more. Also, any changes from 5 to 6 will cer­tainly be eas­ier than 4 to 6 although some I know are hold­ing out till 6 comes out before con­vert­ing. They believe they will have only one upgrade/replacement to go through. I sup­pose this may be true but seems to me, using 5 now will give a more grad­ual slope than going from 4 to 6.
Tagged with:
 

Leave a Reply

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...