gpt4 book ai didi

php - 初始化未定义的命名空间

转载 作者:行者123 更新时间:2023-12-04 17:04:26 26 4
gpt4 key购买 nike

我正在从事一个具有许多功能的大项目。这些功能之一被定义到命名空间中。

当我想初始化一个未定义到命名空间中的类时,我的问题就开始了。这个类没有定义在任何命名空间中,只是整个项目中的一个类。

错误,

Fatal error: Class ... not found ...



我试图包括这个文件,但没有工作。

所以我有:
namespace apps\aaa;

use apps\aaa\bbb;
use apps\cccc\ddd\eee;

class xxx
{
// I tryed to use include_once with the path of the file but doesn't work.
// and in some place into the class, I want to initialize this "unnamedspace class".
$some_var= new unnamedsapceclass();
}

那么,我应该如何处理它?

最佳答案

没有定义命名空间的类属于根命名空间,您可以通过添加命名空间分隔符来指定它:

$some_var= new \unnamedsapceclass();

关于php - 初始化未定义的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17304474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com