note 32909 modified in keyword.extends by danbrown

From: Date: Wed, 17 Jun 2009 19:05:35 +0000
Subject: note 32909 modified in keyword.extends by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157031@lists.php.net to get a copy of this message
a nice example using extends and multiple classes and constructors. <?php 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); ?> --was-- 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); ?> http://php.net/manual/en/keyword.extends.php

« previous php.notes (#157031) next »