找不到具有 PHP 命名空间的类
我之前发布了一些关于在PHP中使用命名空间的问题,从我得到的,我下面的这个示例代码应该可以正常工作。
但是,当我尝试像这样在PHP中使用命名空间时,我遇到了错误。这是按原样运行以下代码时的第一个错误...
Fatal error: Class 'Controller' not found in E:\Controllers\testing.php on line 6
E:\控制器\测试.php文件
<?php
use \Controller;
include('testcontroller.php');
$controller = new Controller;
$controller->show();
?>
E:\Controller\testcontroller.php File
<?php
use \Library\Registry;
namespace Controller
{
class Controller
{
public $registry;
function __construct()
{
include('E:\Library\Registry.class.php');
$this->registry = new Registry;
}
function show()
{
echo $this->registry;
echo '<br>Registry was ran inside testcontroller.php<br>';
}
}
}
?>
E:\库\注册表.class.php文件
<?php
namespace Library\Registry
{
class Registry
{
function __construct()
{
return 'Registry.class.php Constructor was ran';
}
}
}
?>
如您所见,我试图使其尽可能简单,只是为了让命名空间部分正常工作。我尝试了不同的变体,似乎无法弄清楚。