note 68702 deleted from language.oop5 by colder

From: Date: Sun, 19 Aug 2007 23:34:58 +0000
Subject: note 68702 deleted from language.oop5 by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129626@lists.php.net to get a copy of this message
Note Submitter: seva-php at zend dot com ---- Semi-proxy-patterned multi inheritance simulation example: <?php interface INamed { public function getName(); } interface ISon { public function getFather(); } interface IFather { public function getSons(); } abstract class Named implements INamed { protected $name; public function __construct($name) { $this->name = $name; } public function __destruct() {} public function getName() { return $this->name; } } abstract class Son implements ISon { protected $father; public function getFather() { return $this->father; } public function __construct(IFather $father = null) { $this->father = $father; } public function __destruct() {} } abstract class Father implements IFather { protected $sons = array(); public function getSons() { return $this->sons; } public function __construct($sons = array()) { $this->sons = $sons; } public function __destruct() {} } class Man implements INamed, ISon, IFather { public function __construct($name, IFather $father = null, $sons = array()) { // note: these are just __construct() calls - not real class initializations Named::__construct($name); Son::__construct($father); Father::__construct($sons); } public function __destruct() { Named::__destruct(); Son::__destruct(); Father::__destruct(); } public function getFather() { return Son::getFather(); } public function getSons() { return Father::getSons(); } public function getName() { return Named::getName(); } } $siarhej = new Man('Siaroh', new Man('Adas'), array(new Man('Seva'))); var_dump($siarhej->getName()); var_dump($siarhej->getFather()->getName()); $siarhejSons = $siarhej->getSons(); var_dump($siarhejSons[0]->getName()); ?>

« previous php.notes (#129626) next »