note 2802 modified in language.oop by irc-html
| From: | irc-html@php.net | Date: | Sat, 19 Jan 2002 19:38:58 +0000 |
| Subject: | note 2802 modified in language.oop by irc-html | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-25264@lists.php.net to get a copy of this message | ||
Here is some code to demonstrate member objects and inheritance.
class ParentObject {
var $value;
function ParentObject() {
$this->value = 42;
}
}
class MemberObject extends ParentObject {
var $string;
function MemberObject() {
$this->string = "This is a test string.";
$this->ParentObject();
}
}
class ObjTest {
var $ObjPointer;
function ObjTest() {
$tmp = new MemberObject;
$this->ObjPointer = $tmp;
}
}
echo "Creating object of type ObjTest...";
$object = new ObjTest;
echo "Done.<br>\n";
echo "String Contents: " . $object->ObjPointer->string . "<br>\n";
echo "Value Contents: " . $object->ObjPointer->value . "<br>\n";
--was--
Here is some code to demonstrate member objects and inheritance.<br>
<pre>
class ParentObject {
var $value;
function ParentObject() {
$this->value = 42;
}
}
class MemberObject extends ParentObject {
var $string;
function MemberObject() {
$this->string = "This is a test string.";
$this->ParentObject();
}
}
class ObjTest {
var $ObjPointer;
function ObjTest() {
$tmp = new MemberObject;
$this->ObjPointer = $tmp;
}
}
echo "Creating object of type ObjTest...";
$object = new ObjTest;
echo "Done.<br>\n";
echo "String Contents: " . $object->ObjPointer->string . "<br>\n";
echo "Value Contents: " . $object->ObjPointer->value . "<br>\n";
</pre>
http://www.php.net/manual/en/language.oop.php