当前位置: 代码迷 >> PHP >> 小弟我的spl_auto_register()函数为什么只能注册一个自动加载函数呢
  详细解决方案

小弟我的spl_auto_register()函数为什么只能注册一个自动加载函数呢

热度:26   发布时间:2016-04-28 18:08:39.0
我的spl_auto_register()函数为什么只能注册一个自动加载函数呢?

------解决思路----------------------
两个都可以注册成功,你的autoload函数require之前 先要判断是否是文件啊,亲


function __autoload1($className) {    
    $path = 'class/' . $className . ".class.php";
    if (is_file($path))
        require_once 'class/' . $className . ".class.php";
}
function __autoload2($phpFile) {
    $path = $phpFile . ".class.php";
    echo $path;
    if (is_file($path))
        require_once $phpFile . ".class.php";
}
spl_autoload_register('__autoload1');
spl_autoload_register('__autoload2');
$page = new Page;
$person = new Person();
print_r($page);
print_r($person);
  相关解决方案