note 47720 added to language.oop5.overloading

From: Date: Fri, 26 Nov 2004 13:54:12 +0000
Subject: note 47720 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-81060@lists.php.net to get a copy of this message
<?php abstract class BubbleMethod { public $objOwner; function __call($sMethod, $aParams) { // Has the Owner been assigned? if (isset($this->objOwner)) { return call_user_func_array(array($this->objOwner, $sMethod), $aParams); } else { echo 'Owner for ' . get_class($this) . ' not assigned.'; } } } class A_WebPageContainer { private $sName; public function __construct($sName) { $this->sName = $sName; } public function GetWebPageContainerName() { return $this->sName; } } class A_WebFrame extends BubbleMethod { private $sName; public function __construct($sName) { $this->sName = $sName; } public function GetWebFrameName() { return $this->sName; } } class A_WebDocument extends BubbleMethod { private $sName; public function __construct($sName) { $this->sName = $sName; } public function GetWebDocumentName() { return $this->sName; } } class A_WebForm extends BubbleMethod { private $sName; public function __construct($sName) { $this->sName = $sName; } public function GetWebFormName() { return $this->sName; } } class A_WebFormElement extends BubbleMethod { private $sName; public function __construct($sName) { $this->sName = $sName; } public function GetWebFormElementName() { return $this->sName; } } $objWPC = new A_WebPageContainer('The outer web page container.'); $objWF1 = new A_WebFrame('Frame 1'); $objWF1->objOwner = $objWPC; $objWF2 = new A_WebFrame('Frame 2'); $objWF2->objOwner = $objWPC; $objWD1 = new A_WebDocument('Doc 1'); $objWD1->objOwner = $objWF1; $objWD2 = new A_WebDocument('Doc 2'); $objWD2->objOwner = $objWF2; $objWFrm1 = new A_WebForm('Form 1'); $objWFrm1->objOwner = $objWD1; $objWFrm2 = new A_WebForm('Form 2'); $objWFrm2->objOwner = $objWD2; $objWE1 = new A_WebFormElement('Element 1'); $objWE1->objOwner = $objWFrm1; $objWE2 = new A_WebFormElement('Element 2'); $objWE2->objOwner = $objWFrm1; $objWE3 = new A_WebFormElement('Element 3'); $objWE3->objOwner = $objWFrm2; $objWE4 = new A_WebFormElement('Element 4'); $objWE4->objOwner = $objWFrm2; echo "The name of the form that '" . $objWE1->GetWebFormElementName() . "' is in is '" . $objWE1->GetWebFormName() . "'<br />"; echo "The name of the document that '" . $objWE2->GetWebFormElementName() . "' is in is '" . $objWE2->GetWebDocumentName(). "'<br />"; echo "The name of the frame that '" . $objWE3->GetWebFormElementName() . "' is in is '" . $objWE3->GetWebFrameName(). "'<br />"; echo "The name of the page container that '" . $objWE4->GetWebFormElementName() . "' is in is '" .$objWE4->GetWebPageContainerName(). "'<br />"; ?> Results in. The name of the form that 'Element 1' is in is 'Form 1' The name of the document that 'Element 2' is in is 'Doc 1' The name of the frame that 'Element 3' is in is 'Frame 2' The name of the page container that 'Element 4' is in is 'The outer web page container.' By using the abstract BubbleMethod class as the starting point for further classes that are contained inside others (i.e. elements on a form are contained in forms, which are contained in documents which are contained in frames which are contained in a super wonder global container), you can find properties of owner without knowing their direct name. Some work needs to be done on what to do if no method exists though. ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47720 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47720&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47720&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47720&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47720&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47720&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47720&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47720&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81060) next »