为什么这个PHP方法声明无法识别类型提示的命名空间?

时间:2012-01-18 21:22:35

标签: php interface namespaces php-5.3

我正在尝试编写一个基于Doctrine Extensions的库,它提供了这个接口:

namespace Gedmo\Mapping;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;

interface Driver {
  public function readExtendedMetadata(ClassMetadata $meta, array &$config);

  public function setOriginalDriver($driver);
}

在我自己的代码中,我实现了这个接口:

namespace Avit\Schedulable\Mapping\Driver;

use Gedmo\Mapping\Driver,
    Doctrine\Common\Persistence\Mapping\ClassMetadata,
    Doctrine\Common\Annotations\AnnotationReader;

class Annotation implements Driver {
  public function readExtendedMetadata(ClassMetadata $meta, array &$config) {
    // my implementation
  }
}

我得到的错误说明: Avit \ Schedulable \ Mapping \ Driver \ Annotation :: readExtendedMetadata()声明必须与Gedmo \ Mapping \ Driver :: readExtendedMetadata()

如果我删除方法上的ClassMetadata类型提示,我可以避免错误。

我搜索了一些信息,说明当命名空间不匹配时会发生此错误。这是有道理的,因为我在我自己的命名空间中声明了这个类,但是,我正在使用原始ClassMetadata接口使用的Driver的相同Doctrine命名空间。

为什么类型提示无法识别?

1 个答案:

答案 0 :(得分:1)

Driver中的方法 https://github.com/l3pp4rd/DoctrineExtensions/blob/master/lib/Gedmo/Mapping/Driver.php 似乎没有ClassMetadata类型提示。

请注意检查您正在使用的那个?