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 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 cost­ly 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­tain­ly time for PHP coders to aban­don writ­ing any new PHP code that isn’t 100% com­pli­ant with PHP 5, espe­cial­ly stop writ­ting PHP 4 OOP code. It is my per­son­al feel­ing that some of the cur­rent code being pro­duced to be “back­wards com­pat­i­ble” with PHP 4 is real­ly lazy coders not want­i­ng to real­ly learn how to do OOP cor­rect­ly. 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­ni­ty when it comes to tech­nol­o­gy.

I would be rad­i­cal enough to say that the PEAR libraries main­tain­ers should be giv­en a date/time after which if the code is not 100% PHP 5, it gets dropped from the repos­i­to­ry. 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 psue­do-OOP code in the PEAR libraries.

Ironically, I find some of the real­ly old code writ­ten for PHP 3 doesn’t dri­ve me as crazy as the PHP 4 OOP code does. Maybe that is because I think that PHP 4 only was capa­ble of psue­do-OOP and even then, poor­ly. 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 updat­ed. On the oth­er 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 cas­es, just too lazy).

I also have to laugh at some of the pseu­do-OOP code I see done in ver­sion 4. Recently I saw a class that con­sist­ed of sev­er­al 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 like­ly some pre-exist­ing pro­ce­dur­al code that was wrapped in its new OOP cloth­ing and the vars giv­en the $this-> treat­ment. The acces­sor method was there to get the val­ue of the results of the con­struc­tor method. Another class in the same library of code was a bunch of loose­ly tied func­tions that didn’t inter­act with each oth­er or act tech­ni­cal­ly upon the class object. Rather, they act­ed 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 idio­cy.

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

  1. PHP 4 psue­do-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­er­al is much more secure than its pre­de­ce­sors, I feel more secure with PHP 5 although I would real­ly like to see some of the depre­ci­at­ed 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­at­ed stuff should result in bet­ter code.
  4. Eventually, the code is going to have to be upgrad­ed or replaced. PHP 4 is no longer sup­port­ed. PHP 6 will be out soon enough. Upgrading now will pro­vide the cost sav­ings ear­li­er than lat­er. Upgrading lat­er 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­tain­ly be eas­i­er 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.

Leave a Reply