当我尝试从字符串变量构造新类时,它会抛出ClassNotFoundException。我也尝试在名称之前添加类名称空间,但仍无法正常工作。
public function registerCommands(){
$commandMap = $this->getServer()->getCommandMap();
$commands = $this->getCommands();
foreach($commands as $class => $enterName){
$commandMap->register("command", new $class($enterName));
}
}
第二次尝试
public function registerCommands(){
$commandMap = $this->getServer()->getCommandMap();
$commands = $this->getCommands();
foreach($commands as $class => $enterName){
$class = "\\server\utils\CommandReader\\" . $class;
$commandMap->register("command", new $class($enterName));
}
}
$ class是string