php - 未找到但使用命名空间定义的类
问题描述
我有一个DataBaseHelper
在文件中定义的类DataBaseHelper.php
:
<?php
namespace Company\Project\System\DataBaseHelper;
use Company\Project\System\RepoLink;
use mysqli;
use mysqli_result;
class DataBaseHelper
{
/* some cool stuff */
}
在一个名为helper.php
(带有命名空间Company\Project\System;
)的文件中,我使用以下 use 语句use Company\Project\System\DataBaseHelper\DataBaseHelper;
::
<?php
namespace Company\Project\System;
use Company\Project\DataBaseHelper\DataBaseHelper\DataBaseHelper;
class CustomHelper
{
/* some cool stuff */
public function getDownloadCount(): string
{
try {
$query = "SELECT sum(count) c from downloads";
// The next line is line 258
$DBLink = new DataBaseHelper();
$result = $DBLink->getAssocResult($DBLink->executeQuery($query));
return $result["c"];
} catch (\Exception $e) {
// TODO: Errorhandling
return "ERROR";
}
}
}
调用CustomHelper->getDownloadCount()
会引发以下错误:
> [15-Sep-2019 07:48:09 Europe/Berlin] PHP Fatal error: Uncaught Error: Class 'Company\Project\System\DataBaseHelper\DataBaseHelper'
> not found in
> /Applications/XAMPP/xamppfiles/htdocs/project/system/helper.php:258
> Stack trace:
> #0 /Applications/XAMPP/xamppfiles/htdocs/project/manage/index.php(49):
> Company\Project\System\RepoHelper->getDownloadCount()
> #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/project/system/helper.php on
> line 258
命名空间是否缺少任何东西?里面的use Statementhelper.php
是我的IDE(PHPStorm)自动生成的。
我不使用任何框架。
解决方案
推荐阅读
- sql - 大查询查找可能位于多列中的数据
- salesforce - 发送电子邮件警报的工作流程规则
- jenkins - 在成功的 Github Actions 工作流上触发 Jenkins 作业
- permissions - 没有用户或角色对 SQL Server 表具有 SELECT 权限,但用户可以从中选择行
- c# - Java 的 C# 等效项 @DynamoDBTyped(DynamoDBAttributeType.BOOL)
- c - 将非数组变量的地址传递给声明为“Type ptr[static 1]”的函数参数是否有效?
- python - 虽然声明是 heroku discord bot 在一段时间后停止工作
- java - 在多级继承的情况下,如何编写一个类以将对象创建限制为一次?
- python - Python 3“getitem__(self, key)”简单错误/问题
- c++ - 交叉编译:添加符号时出错:文件格式错误 collect2:错误:ld 返回 1 退出状态