1

我有类型提示的问题。我有这样的类(伪代码):

interface iBaseDAO
{
    public function __construct(iBaseDataMapper $objDataMapper);
    //...
}

interface iBaseDataMapper
{
    //...
}

interface iConcreteDataMapper extends iBaseDataMapper
{
    //...
}

class ConcreteDAO implements iBaseDAO
{
    public function __construct(iConcreteDataMapper $objDataMapper)
    {
        //...
    }
}

我想实现,DAO只能用某种实例化,DataMapperConcreteDAO要确保它只能用ConcreteDataMapper. 因为iConcreteDataMapperiBaseDataMapper我认为它应该工作的孩子,但我收到错误:

Fatal error: Declaration of ConcreteDAO::__construct() must be compatible with iBaseDAO::__construct(iBaseDataMapper $objDataMapper)

为什么我不能使用iConcreteDataMapperin ConcreteDAO?感谢您的任何帮助。

4

0 回答 0