I have one file DHMOFramework/lib/Core/Core.php with this code:
<?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;
}
}
And I have another file test.php with this code:
<?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>");
And I keep getting this error when I run the test.php file:
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
How ca I fix this?
Use full class name:
$dhmo = new DHMOFramework\lib\Core\Core\Core();
Or use a use
statement before using the class:
use DHMOFramework\lib\Core\Core\Core;
$dhmo = new Core();
Check out Namespaces in Official PHP documentation