我正在将 Symfonys Autoloader 用于具有以下文件夹/类结构的项目:
App
+- Package1
|
+- Package2
+- Class1.php
|
- Interface1.php
我现在如何从父命名空间实现一个类。
喜欢
Interface1
来自 Class1
例如。这不起作用:
namespace App\Package1
Class1 implements App\Interface1
{
//implement some functions here...
}
Autoloader 尝试包含
App\Package2\Class1\App\Interface1
然后。最好的祝福,
曼努埃尔
最佳答案
symfony 的类加载器很好用:)
在这种情况下,这是一个 php 语法问题。
您需要使用“use”或更轻松地导入命名空间,您只需要在类名前加一个反斜杠
例如:
namespace App\Package1;
use App\Interface1;
Class1 implements Interface1
{
//implement some functions here...
}
或者
namespace App\Package1;
Class1 implements \App\Interface1;
{
//implement some functions here...
}
关于php - Symfonys Autoloader - 实现父命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15440264/