很长时间没做PHP开发,刚刚在开发过程中发现使用了 Smarty 3.1.14 后,原先写的PHP __autoload 不能使用,查看很久发现这个版本的smary里面使用 spl_autoload_register 已经注册了一个 __autoload
vim Smarty.class.php +83
if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
spl_autoload_register();
}
} else {
spl_autoload_register('smartyAutoload');
}
故需要重新注册一个以区别
/*
function __autoload($class_name) {
echo $class_name;
if (!include_once($class_name . '.php')) {
throw new Exception('no class');
}
}
*/
//PHP 5.3 以上写法
spl_autoload_register(function ($class_name) {
if (!include_once($class_name . '.php')) {
throw new Exception('no class');
}
});
如果用版本较低的版本
可以参考下
http://us3.php.net/manual/en/function.spl-autoload-register.php
备忘。。