Then give it a implementation of BInterface. Just because the create function has AInterface passed in doesn't mean you have to new up SuperClass with it.
$class = new SuperClass(new ThingThatImplementsBInterface());
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey hey :)
I'm trying to use the SOLID-principles, however, I have a problem with Type-Hinting.
First, have a look at my code, but it is important to note: $a implements AInterface and BInterface.
public function create(AInterface $a): void
{
...
$class = new SuperClass($a); //---> here is the problem, it wants BInterface, not AInterface
..
}
For the first create method, we just care about the AInterface-Methods
Inside of SuperClass we just care about the BInterface-Methods
However, my intelephense writes, that the type is wrong.
Currently, I just merged AInterface and BInterface together, but Interface Segregation states that we should not force to use a method when not used.
How would you do this?
I've looked it up and some solutions are using a third interface, extending AInterface and BInterface.
Please or to participate in this conversation.