pool = array(); } /** * Adds an Instance of Bar to the Pool. * @param Bar $bar * @return void */ public function addBar($bar) { array_push($this->pool, $bar); } /** * Returns the internal instance of Bar for the specific ID. * @param int $id * @return Bar */ public function getBar($id) { return $this->pool[$id]; } /** * Outputs the current state of the bars in the pool. * @return void */ public function getTestResult() { foreach($this->pool AS $id=>$bar) { echo "ID: " . $id . ", Test: " . $bar->test . "\n"; } } } /** * Testclass #2 * @author jpt */ class Bar { /** * @var string Teststring. */ public $test; /** * Default constructor. Initializes test variable. * @return void */ function __construct() { $this->test = "failed"; } } $f = new Foo(); $f->addBar(new Bar()); $f->addBar(new Bar()); $f->addBar(new Bar()); $f->addBar(new Bar()); $f->getBar(1)->test = "success"; $f->getTestResult(); ?>