Jump to content
ckrudelux

parent::

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

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...