This topic created in 4663 days ago, the information mentioned may be changed or developed.
init.inc.php的内容
//自动挂载类
function AutoLoad($classname){
// class类
$filepath = BASE_CLASS . $classname . '.class.php';
if (file_exists($filepath)) {
return include $filepath;
}
//lib库文件
$filepath = BASE_LIB . $classname . '.lib.php';
if (file_exists($filepath)) {
return include $filepath;
}
}
spl_autoload_register('AutoLoad');
在建一个test.class.php放在class文件夹下
class test{
function method(){
echo 'Hello world';
}
}
然后index.php
require 'init.inc.php';
AutoLoad('test');
$test = new testclass();
$test->method();
如果在init.inc.php中注释掉spl_autoload_register('AutoLoad');
一样成功,问题就来了,spl_autoload_register有什么用呢?
3 replies • 1970-01-01 08:00:00 +08:00
 |
|
1
donwa Aug 3, 2013 via iPhone 1
不用autoload('test'); 找不到类它会自己执行autoload
|
 |
|
3
xiaokai Aug 3, 2013
这不应该成功嘛 $test = new testclass(); ?
|