Given:
class Foo {
private $bar;
public function setBar(Bar $bar) {
$this->bar = $bar;
}
}
Is there any way to call setBar()
with a parameter that is not an instance of Bar
?
$proxy = new Proxy();
$foo = new Foo();
$foo->setBar($proxy);
// with
class Proxy {
}
The idea is to inject a proxy object instead of a Bar
instance. The Proxy
class is generic (in a dependency injection framework) and cannot be made to implement/extend Bar
.
The Reflection API doesn't seem to provide anything making that possible. I'm looking to do that without using a PHP extension (standard PHP install > 5.3) (and I'm trying to leave eval
alone if possible).
Note: yes this is weird stuff, I'm expecting comments about that, but please leave the "answers" for actual answers to the question. This is not intended to be production code.