I am trying to autoload classes that are in different folders. Is that possible?
function __autoload($class){
require $class.'.php';
require 'libs/'.$class.'.php';
//this won't work.
}
I want to autoload classes that are either in libs folder or on the root. Any thoughts? Thanks a lot.
First, I suggest you look into
spl_autoload_register, which is superior for doing this.Second, you should use
is_fileto test whether the file exists, then try to load it. If yourequirea file that doesn’t exist, your script will halt.If you have multiple folders where the file could be, you could do something like this: