Framework solution
By now, I hope that you are persuaded by architectural security and practical coding considerations that development is best done by the creation of as many classes as are needed to solve the problem, with each usually in its own file. Fortunately, PHP 5 is clearly designed to support this scenario. How does it do it?
Autoloading
In version 5.1.2, PHP provides an improved version of what we need: the spl_autoload_register
function. We are going to build our class management logic into a class called smartClassMapper
. It will have a subclass called smartAdminClassMapper
, which also knows about the classes used exclusively on the administrator side of our CMS, but is not described in any detail here. Our call to set up autoloading for the CMS is made very early in the processing of each request and consists of:
spl_autoload_register(array('smartClassMapper', 'autoloadClass'));
The PHP function expects a callback as the parameter, and we supply an array to indicate that...