After running an extended web search for the PHP __autoload()
magic method, I was struck by the fact that none of the most useful resources found ever mentioned a basic aspect of this method, namely the underlying include path settings. Either we're talking about basic tutorials or
more advanced strategies, nobody seems to take this setting into account. In short, __autoload()
works by searching for files with a given class name in your include path. If it doesn't find a file in your include path, it raises an error.
So the first thing to do is to properly set your include path to make __autoload()
work as expected. I found two useful resources that may help you with this:
- Setting your include path (PHP Manual)
- Location, location, location!, which takes into account the Zend Framework but it can be applied to all the MVC frameworks as well.