<?php class Foo { private $bar; public function getBar() { return $this->bar; } public function setBar($bar) { $this->bar = $bar; } } class Baz { private $container; public function add(Foo $foo) { $this->container[] = $foo; } public function getFirstOrDefault() { return isset($this->container[0]) ? $this->container[0] : null; } } $foo = new Foo(); $baz = new Baz(); $baz->add($foo); var_dump($baz->getFirstOrDefault()->getBar()); $foo->setBar('baz'); var_dump($baz->getFirstOrDefault()->getBar());
You have javascript disabled. You will not be able to edit any code.