jeudi 4 mars 2021

How can I specify argument in implementation of interface in PHP

I have two intefaces and First uses Second as an argument but I can't use an implementation of Second as argument to First's metod (Declaration must be compatible). Is there any solutions or patterns for it?

Example:

interface iFirst
{
    public function fMethod(self $a) : bool;
}

interface iSecond {
    public function sMethod(iFirst $a);
}

class FirstImplemevtation implements iFirst
{
    public function fMethod(self $a) : bool //Declaration must be compatible
    {
    }
}

class SecondImplementation implements iSecond 
{
    public function sMethod(FirstImplemevtation  $a) //Declaration must be compatible
    {
    }
}

Aucun commentaire:

Enregistrer un commentaire