Selective PHP autoload

Posted by Extrakun on Stack Overflow See other posts from Stack Overflow or by Extrakun
Published on 2010-04-09T07:55:14Z Indexed on 2010/04/09 8:03 UTC
Read the original article Hit count: 459

Filed under:

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.

  1. Does autoload only kicks in if a class name is not defined?

  2. 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!

© Stack Overflow or respective owner

Related posts about php