【发布时间】:2017-01-14 19:24:58
【问题描述】:
我有一个包含以下代码的文件 DHMOFramework/lib/Core/Core.php:
<?php
namespace DHMOFramework\lib\Core\Core;
/**
* Main DHMOFramework class
*/
$registeredCommands = [];
class Core
{
function registerCommand($command) {
global $registeredCommands;
$registeredCommands[$command] = [];
}
function registerSubCommand($commandname, $subcommand, $args, $helpmsg) {
global $registeredCommands;
$structure = array('command' => $commandname, 'subcommand' => $subcommand, 'args' => $args, "helpmsg" => $helpmsg);
array_push($registeredCommands[$commandname], $structure);
echo $registeredCommands;
}
}
我还有另一个文件 test.php 包含此代码:
<?php
require_once "DHMOFramework/lib/Core/Core.php";
$dhmo = new Core();
$dhmo->registerCommand("command");
$dhmo->registerSubCommand("command", "subcommand", ["arg1" => [true, string], "arg2" => [true, boolean]], "Usage: /command subcommand <arg1> <arg2>");
当我运行 test.php 文件时,我不断收到此错误:
Fatal error: Class 'Core' not found in /home/ubuntu/workspace/test.php on line 5
Call Stack:
0.0001 232464 1. {main}() /home/ubuntu/workspace/test.php:0
我该如何解决这个问题?
【问题讨论】:
-
请包含两个文件的绝对路径。即:/home/ubuntu/workspace/test.php 但是 DHMOFramework/lib/Core/Core.php 相对于您的工作区在哪里? (如果你只拥有整个东西就更好了,比如它可能位于 /home/ubuntu/workspace/DHMOFramework/lib/Core/Core.php ?)