note 32909 added to keyword.extends
| From: | quinton at free dot fr | Date: | Tue, 10 Jun 2003 18:07:10 +0000 |
| Subject: | note 32909 added to keyword.extends | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50119@lists.php.net to get a copy of this message | ||
a nice example using extends and multiple classes and constructors.
<?
class CoreObject {
var $name;
function CoreObject($name){
$this->_constructor($name);
}
function _constructor($name){
$this->name = $name;
}
function show(){
printf("%s::%s\n", $this->get_class(), $this->name);
}
function get_class(){
return get_class($this);
}
}
class Container extends CoreObject{
var $members;
function Container($name){
$this->_constructor($name);
}
function &add(&$ref){
$this->members[] = $ref;
return ($ref);
}
function show(){
parent::show();
foreach($this->members as $item){
$item->show();
}
}
function apply(){
}
}
class Person extends CoreObject{
function Person($name){
$this->_constructor($name);
}
}
class Family extends Container {
var $members;
function Family($name){
$this->_constructor($name);
}
}
echo "<pre>\n";
$family = new Family('my family');
$family->add(new Person('father'));
$family->add(new Person('mother'));
$family->add(new Person('girl'));
$family->add(new Person('boy'));
$family->show();
print_r($family);
?>
----
Manual Page -- http://www.php.net/manual/en/keyword.extends.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32909
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32909&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32909&report=yes