1
我有一個名爲Query.php的文件。PHP名稱空間和自動加載不起作用
namespace Test
{
class Query
{
public function __construct()
{
printf("Hello, World");
}
}
}
在bootstrap.php中我嘗試調用它:
spl_autoload_register(function($className) {
if(file_exists('../folder/'.$className.'.php'))
{
require_once '../folder/'.$className.'.php';
}
});
new \Test\Query();
結果:致命錯誤:未找到類測試\查詢。
沒有命名空間它工作正常。如何解決它?
在此先感謝。
哪裏是你的'spl_autoload_register'實現?它不會奇蹟般地知道從哪裏加載類。如果你有一個,那就是錯誤所在。 – 2014-10-10 13:40:18
@JuanMendes,對不起。我添加了它。 – 2014-10-10 13:41:49
你真的有一個名爲文件夾的文件夾? – 2014-10-10 13:46:04