note 24897 added to language.oop

From: Date: Wed, 04 Sep 2002 10:27:26 +0000
Subject: note 24897 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-36094@lists.php.net to get a copy of this message
class Diary { var $_entries = array(); function addEntry($entry) { array_unshift($this->_entries, $entry); } function getEntry($num) { return $this->_entries[$num]; } } class Entry { var $_entrytext; function Entry($entrytext) { $this->_entrytext = $entrytext; } function getText() { return $this->_entrytext; } } $d = new Diary; $e1 = new Entry("My Text"); $d->addEntry($e1); $e2 = $d->getEntry(0); //Everything so far appears to work without error. //However trying this. echo $e2->getText(); //returns nothing echo $e2 //prints "Object" //however echo $e2->getText(); //prints "My Text" as expected. --------------------- Is this a problem caused by $e2 not being of type Entry, and if so how can I rectify this? using $d->getEntry(0)->getText(); produces as parse error. -- http://www.php.net/manual/en/language.oop.php http://master.php.net/manage/user-notes.php?action=edit+24897 http://master.php.net/manage/user-notes.php?action=delete+24897 http://master.php.net/manage/user-notes.php?action=reject+24897

« previous php.notes (#36094) next »