note 61745 added to language.oop5.magic
| From: | ksamvel at gmail dot com | Date: | Fri, 10 Feb 2006 17:29:13 +0000 |
| Subject: | note 61745 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103466@lists.php.net to get a copy of this message | ||
To copy base part of derived class appropriate method in base should be defined. E.g.:
class A {
public function setAVar( $oAVar) { $this->oAVar = $oAVar; }
public function getAVar() { return $this->oAVar; }
public function copyA( &$roDest) {
if( $roDest instanceof A)
$this->oAVar = $roDest->oAVar;
}
private $oAVar;
}
class B extends A {
public function setBVar( $oBVar) { $this->oBVar = $oBVar; }
public function getBVar() { return $this->oBVar; }
private $oBVar;
}
$oA = new A();
$oB = new B();
$oA->setAVar( 4);
$oB->setAVar( 5);
$oB->setBVar( 6);
echo "oA::oAVar " . $oA->getAVar() . "<br>";
echo "oB::oAVar " . $oB->getAVar() . "<br>";
echo "oB::oBVar " . $oB->getBVar() . "<br>";
echo "<br>";
$oB->copyA( $oA);
echo "oA::oAVar " . $oA->getAVar() . "<br>";
echo "oB::oAVar " . $oB->getAVar() . "<br>";
echo "oB::oBVar " . $oB->getBVar() . "<br>";
Output:
oA::oAVar 4
oB::oAVar 5
oB::oBVar 6
oA::oAVar 4
oB::oAVar 4
oB::oBVar 6
----
Server IP: 64.246.30.37
Probable Submitter: 131.225.163.89
----
Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61745
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61745&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61745&report=yes
Search -- http://master.php.net/manage/user-notes.php