Jump to content

parent::


ckrudelux
 Share

Recommended Posts

<?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;  }}

Edited by ckrudelux
Link to comment
Share on other sites

$this->message[] = $message; OR $this->messages[] = $message;
Hm.. didn't see that in my example, have an other larger code with this problem but I thought I would save you the trouble of looking it through. But then I got it confirmed what miss type was the problem, and yes it was the same in the real deal but damn hard to see what it was... cause this miss type was caused of not using the uppercase in the beginning of the property name. Thanks anyway :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...