note 68702 added to language.oop5

From: Date: Tue, 08 Aug 2006 08:35:46 +0000
Subject: note 68702 added to language.oop5
Groups: php.notes 
Request: Send a blank email to php-notes+get-115623@lists.php.net to get a copy of this message
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()); ?> ---- Server IP: 192.117.122.43 Probable Submitter: 80.74.124.188 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.php Edit -- https://master.php.net/note/edit/68702 Del: integrated -- https://master.php.net/note/delete/68702/integrated Del: useless -- https://master.php.net/note/delete/68702/useless Del: bad code -- https://master.php.net/note/delete/68702/bad+code Del: spam -- https://master.php.net/note/delete/68702/spam Del: non-english -- https://master.php.net/note/delete/68702/non-english Del: in docs -- https://master.php.net/note/delete/68702/in+docs Del: other reasons-- https://master.php.net/note/delete/68702 Reject -- https://master.php.net/note/reject/68702 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115623) next »