Modernize Your Legacy PHP Application

How? Code base restructuring. As suggested by the video presentation below, these are the recommended 2 steps.

1. Consolidate classes for autoloading.
Just implement autoloading according to PSR-0 specification. Move php script around and remove all the require or include statement. Do make sure is one class per file.

Also, group all your helper functions into classes and call these global functions through static or instance method. Example of static method.
xxx_get() to XXX::get()
xxx_set() to XXX:set()

Some of you may argue this does not bring any sort of benefits except more typing. I do agree as occasionally we sometimes have a few orphaned global functions which hard to be grouped in any class. Surely we're not going to put these helper functions in a class called Miscellaneous or Common class.

2. Convert global to injected dependencies
Those dreadful global variables (those using global keyword) which sometimes accidentally which values may reassigned half way through your script.

No comments:

Post a Comment