PHP-Code:
<?php
class Demo {
privtate $reference = null;
public function __construct($reference) {
$this->reference = $reference;
}
public function testMethod() {
$this->reference->foo();
}
}
class Bar {
public function foo() {
echo __METHOD__;
}
}
$obj = new Demo(new Bar());
$obj->testMethod();
?>
Teste es.