PHP: autoload and include path

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:

  1. Setting your include path (PHP Manual)
  2. Location, location, location!, which takes into account the Zend Framework but it can be applied to all the MVC frameworks as well.

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.