I have an spl_autoload being called but the problem is the second autoload does not execute and I can’t figure out why. With this code this code the script should die. I remove classes from folder array, the autoload will work. My code looks like this:
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors','On');
/*** nullify any existing autoloads ***/
spl_autoload_register(null, false);
/*** specify extensions that may be loaded ***/
spl_autoload_extensions('.php');
function dataLoader($class) {
foreach (array(PV_CORE.DS.'data'.DS, PV_CORE.DS.'system'.DS, PV_CORE.DS.'cms'.DS, PV_CORE.DS.'util'.DS,PV_CORE.DS.'components'.DS, PV_CORE.DS.'template'.DS) as $folder){
if (is_file($folder.$class.'.php')) {
include_once $folder.$class.'.php';
}
}//end foreach
}
function testLoader($class) {
die();
$filename = $class. '.php';
$file =PV_CORE.DS.'data'.DS.$filename;
if (!file_exists($file)) {
return false;
}
require_once $file;
}
spl_autoload_register('dataLoader');
spl_autoload_register('testLoader');
Your code works but probably a misunderstanding.
Your functions are registered:
returns:
and if you initialize a class
dataLoader will try to load the file:
Your script will only load the second or any other registered function if he can’t find the class in the first place.
So if you remove your $class in the function dataLoader __autoload wont find the class anymore in the first registered function so he will try to look up for it in the second registered function and so on.