我想使用__autoload函数..例如,我在同一个文件夹中有两个文件:
index.php,MyClass.php
MyClass.php是这样的:
// filename: MyClass.php
namespace SomeNameSpace;
class MyClass{
public static function helloWorld(){ echo 'Hello'; }
}
所以我想要做的是使用__autoload来加载这个类 . 但是当我这样做时:
function __autoload($className){
include($className.'.php');
}
autoload不起作用,因为该类在命名空间中 .
有帮助吗?
index.php的示例:
//index.php
//the autoload method above
SomeNameSpace\MyClass::helloWorld();
1 回答
当你在做的时候
你实际上正在寻找一个名为“$ classname.php”的文件 . 删除单引号 .
尝试: