note 24897 rejected from language.oop by betz
| From: | betz@php.net | Date: | Wed, 04 Sep 2002 11:53:40 +0000 |
| Subject: | note 24897 rejected from language.oop by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-36102@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.