当前位置 : 主页 > 网络编程 > PHP >

Common类实现自动调用方法和注册方法

来源:互联网 收集:自由互联 发布时间:2021-06-28
autoload.php class Common{ public static function autoload($class_name){ if (file_exists('../oop/day1/'.$class_name.'.class.php')){ include '../oop/day1/'.$class_name.'.class.php'; }else { echo '没有找到类文件:'.'\'../oop/day1/'.$cla
autoload.php
class Common
{
    public static function autoload($class_name)
{
    if (file_exists('../oop/day1/'.$class_name.'.class.php')){
        include '../oop/day1/'.$class_name.'.class.php';
    }else {
        echo '没有找到类文件:'.'\'../oop/day1/'.$class_name.'.class.php\'';
        return false;
    }
}
    public static function register()
    {
        spl_autoload_register('self::autoload');
    }
}

//调用
Common::register();
网友评论