简而言之,我有
abstract class AbstractMapper implements MapperInterface {
public function fetch(EntityInterface $entity, Array $conditions = array()) {
. . .
}
}
interface MapperInterface {
public function fetch(EntityInterface $entity, Array $conditions = array());
}
abstract class AbstractUserMapper extends AbstractMapper implements UserMapperInterface {
public function fetch(UserInterface $user, Array $conditions = array()) {
$conditions = array_merge($conditions, array('type' => $user->getType()));
return parent::fetch($user, $conditions);
}
}
interface UserMapperInterface {
public function fetch(UserInterface $user, Array $conditions = array());
}
这是我得到的错误:
致命错误:Model\Data\Mappers\AbstractUserMapper::fetch() 的声明必须与 Model\Data\Mappers\Interfaces\MapperInterface::fetch() 的声明兼容
如果我将其更改UserInterface为EntityInterface它可以工作,但它似乎是错误的,而且在AbstractUserMapper::fetch()我键入时,$user我的 IDE 仅显示我声明的方法,EntityInterface而getType()不是在该列表中。
我知道我仍然可以放置$user->getType(),因为我知道我拥有的对象实现了UserInterface但这一切似乎都是错误的,即使我的 IDE 也这么认为,还是我在这里遗漏了什么?
为什么这不起作用?EntityInterface如果我必须输入而不是 'UserInterface我认为它会弄乱我的代码。