Selective PHP autoload
- by Extrakun
I am writing a add-on module which is integrated with an existing PHP application; Because I am using a MVC pattern, and which may requires lot of inclusion of classes (which might not be used at all depending on the action of the user), I decide to use autoloading of classes.
However, I have to ensure that the autoload function does not interferes with the normal operations of the existing applications.
Does autoload only kicks in if a class name is not defined?
Say I have to write another module which uses its own autoload functions (say, I have an autoload for a module, since they each reside in their own folder), how do I differentiate which module is it for?
For #2, I thought of 2 options. Either prefix the class name with the module name (Such as 'MyNewModule_View_Default' and 'AnotherModule_View_Default'), or use file_exists to check the include file exists.
Other suggestions are welcomed too!