how to instantiate an interface with a class in PHP?
<?php
interface ParentInterface {
public function sayHi() : string;
}
class A implements ParentInterface {
private function foo(){
return 'foo';
}
public function sayHi() : string {
echo 'hi!' . $this->foo();
}
}
class B implements ParentInterface {
private function bar(){
return 'bar';
}
public function sayHi() : string {
echo 'hi!' . $this->bar();
}
}
$binded = new ParentInterface;
//how I will tell the interface to instantiate that class I want on the base of some condition.
var_dump($binded->sayHi());