dsfjnxjlbqv9812 2013-03-15 19:04
浏览 70
已采纳

Symfonys Autoloader - 实现父命名空间

I am using Symfonys Autoloader for a project having the following folder/class structure:

App
+- Package1
|
+- Package2
  +- Class1.php
|
- Interface1.php

How do i implement a class from a parent namespace now. Like Interface1 from Class1 for example. This does not work:

namespace App\Package1

Class1 implements App\Interface1
{
    //implement some functions here...
}

The Autoloader trys to include App\Package2\Class1\App\Interface1 then.

Best regards,

Manuel

  • 写回答

1条回答 默认 最新

  • dqr3883 2013-03-15 19:11
    关注

    the symfony's classloader works great:)

    In this case, it's a php syntax problem.

    You need to import the namespace with "use" or more easily you just need a backslash in front of the classname

    for example:

    namespace App\Package1;
    
    use App\Interface1;
    
    Class1 implements Interface1
    {
        //implement some functions here...
    }
    

    or

    namespace App\Package1;
    
    Class1 implements \App\Interface1;
    {
        //implement some functions here...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?