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

 

posted @ 2015-03-08 22:39  KoMiles  阅读(396)  评论(0编辑  收藏  举报