我正在尝试自动加载一个类,但我的自动加载器似乎没有正确注册。
Folder/File structure
:
**zest.php**
:
<?php
$aThing = new a;
$aThing->test();
function my_autoloader($class) {
include 'aest/' . $class . '.thing.php';
}
spl_autoload_register('my_autoloader');
?>
**a.thing.php**
:
<?php
class a {
public function test() {
echo 'test';
}
}
我直接从php.net中提取了这个例子,它出了什么问题?
根本不会调用自动加载器功能。
即使是强大的功能也不行:
spl_autoload_register(function($class) {
echo 'calling '.$class;
include 'aest/'.$class . '.test.php';
});
答案 0 :(得分:0)
在尝试实例化必须自动加载的类之前,必须调用... spl_autoload_register('AutoLoader')
。