PHP中spl_autoload_register()函数

spl_autoload_register — 注册给定的函数作为 __autoload 的实现

官方地址:http://php.net/manual/zh/function.spl-autoload-register.php

我的测试

定义三个文件test.php test1.php test2.php

test.php

<?php

spl_autoload_register('autoLoad1');

test1::test();
echo "<br/>"; test2::test(); function autoLoad1($
class) { require $class.'.php'; }

test1.php

<?php

class test1 {
    static public function test() {
        echo __FILE__;
    }    
}

test2.php

<?php

class test2 {
    static public function test() {
        echo __FILE__;
    }    
}    

运行test.php

原文地址:https://www.cnblogs.com/wangkongming/p/4322462.html