If there must be multiple autoload functions, spl_autoload_register() allows for this. It effectively creates a queue of autoload functions, and runs through each of them in the order they are defined. By contrast, __autoload() may only be defined once.
第二個參數是如果加載不到是否拋出異常
第三個參數是是否加入到隊列頭部
第二個參數是如果加載不到是否拋出異常
第三個參數是是否加入到隊列頭部
2016-08-22
function library($class) {
$file = DIR_SYSTEM . 'library/' . str_replace('\\', '/', strtolower($class)) . '.php';
if (is_file($file)) {
include_once(($file));
return true;
} else {
return false;
}
}
spl_autoload_register('library');
spl_autoload_extensions('.php');
$file = DIR_SYSTEM . 'library/' . str_replace('\\', '/', strtolower($class)) . '.php';
if (is_file($file)) {
include_once(($file));
return true;
} else {
return false;
}
}
spl_autoload_register('library');
spl_autoload_extensions('.php');
2016-08-22