Let's say I have class:
class Foo implements FooInterface{
private $a=2;
//implements sum from interface
public function sum(){
return $a+$a;
}
}
Now I have another class:
class Bar{
private $foo;
public function __construct($foo){
$this->foo = $foo;
}
}
PHP let's us force object type while calling methods:
function abc(Xyz $xyz){}
Does it supports forcing interfaces? Can I force constructor of Bar
to accept only objects that implement FooInterface
?