Suppose I need to automatically include files (classes) from different directories. But if I write an autoloader according to my knowledge, the following picture appears:

function __autoload($class) { if(is_file('controllers/' . $class . '.php')) include_once 'controllers/' . $class . '.php'; } 

I check for the file in the controllers directory. Is it possible to set the directories by which files should be searched?

2 answers 2

Why not just look in the directory list?

 foreach (array('dir1', 'dir2', 'dirN') as $dir) { if(is_file($dir . '/' . $class . '.php')) include_once $dir . '/' . $class . '.php'; } 

    http://symfony.com/doc/current/components/class_loader.html