出于某种原因,我在类文件中遇到了带有命名空间的spl_autoload_register问题。如果我在没有spl_autoload_register的情况下以正常方式包含该类,它就可以正常工作。当我尝试使用spl_autoload_register时它会停止工作并且php会抛出错误。
以下是我的测试文件: info.php的
<?php
include '../class/soapConn.php';
spl_autoload_register(
function ($class) {
include '../class/' . $class . '.php';
}
);
// include '../class/lists.php'; //This works with the name space!
if (isset($_GET["data"]) && $_GET["data"] == "test") {
$schoolsList = new \DBviewer\lists($client); //Can't find the class?
$array=[];
$array = $schoolsList->getSchools();
echo json_encode($array);
}
类文件: lists.php
<?php
namespace DBviewer;
include '../class/soapConn.php';
class lists {
function __construct($client) {
$this->client=$client;
}
function getSchools() {
//random stuff here
return $array;
}
}
知道自动加载为什么会给我带来问题?我做错了什么?