自动加载简单实现 __autoload()

./index.php 入口文件
function __autoload($classname) {
    $filename = "./". $classname .".php";
    include_once($filename);
}

// we've called a class ***
$obj = new myClass();
//myClass.php
class myClass {
    public function __construct() {
        echo "myClass init'ed successfuly!!!";
    }
}

思考:其实自动加载就是省去自己手写多个include_once文件,让复用自动加载函数引入需要include_once的文件

猜你喜欢

转载自www.cnblogs.com/zxqblogrecord/p/9964760.html