<?phpclass test { private $messages = array(); public function addMessage($message){ $this->message[] = $message; } public function getMessages(){ return $this->messages; } } class test2 extends test{ public function getMessages(){ $this->addMessage("Last message."); return parent::getMessages(); }} $test2 = new test2();$test2->addMessage("Hello World");print_r($test2->getMessages());
In my world of understanding this should return an array with 2 entries but I get an empty array back, anyone know what's wrong? What the code does is what class test2 overwrites getMessages and adds a message and calls back to the parent method to do the original script of the function. odd is this work:
class test2 extends test{ public function getMessages(){ $this->addMessage("Last message."); return $this->messages; }}