In this code:
class Foo {
private $foo;
public function Foo($foo) {
$this->foo = $foo;
}
public function getFoo() {
return $this->foo;
}
}
$a = new Foo(new Foo('bar'));
echo $a->getFoo()->getFoo();
In old php I’ll coudn’t call second getFoo I’ll need to assign it to some variable. Which version of php added this feature?
Maybe in a really old PHP version. It wouldn’t work in PHP 4, because returning
$this->foowould return by value, and not by reference. Returning&$this->foowould work though. Since PHP 5.0 (if I recall correctly), objects are always returned by reference, so the code above should work without problems in PHP >= 5.