in short have
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()); }
this error get:
fatal error: declaration of model\data\mappers\abstractusermapper::fetch() must compatible of model\data\mappers\interfaces\mapperinterface::fetch()
if change userinterface
entityinterface
works seems wrong , in abstractusermapper::fetch()
when type$user
ide shows methods declared in entityinterface
, gettype()
not in list.
i know can still put $user->gettype()
because know object have implements userinterface
seems wrong, ide thinks or missing here?
why not work? messing code if have put entityinterface
instead of 'userinterface
think.
the problem lies here:
abstract class abstractusermapper extends abstractmapper implements usermapperinterface
as first step, inspect definition of abstractmapper
:
abstract class abstractmapper implements mapperinterface
interface definitions between parent , child classes transitive, can merge first definition:
abstract class abstractusermapper extends abstractmapper implements usermapperinterface, mapperinterface
this means class needs implement:
public function fetch(entityinterface $entity, array $conditions = array()); public function fetch(userinterface $user, array $conditions = array());
and not possible, because method overloading doesn't exist in php.
possible solution
assuming following interface definitions:
interface entityinterface {} interface userinterface extends entityinterface {}
i suggest drop implements usermapperinterface
:
abstract class abstractusermapper extends abstractmapper
Comments
Post a Comment