note 72110 rejected from language.oop.constructor by nlopess
| From: | nlopess@php.net | Date: | Wed, 03 Jan 2007 12:18:01 +0000 |
| Subject: | note 72110 rejected from language.oop.constructor by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121234@lists.php.net to get a copy of this message | ||
Note Submitter: jedacz at tlen dot pl
----
Can someone tell wether it's a bug or correct object model interpretation by php?
<?
class A
{
protected $var = 'one ';
public function getVar()
{
return $this->var;
}
}
class B extends A
{
protected $var = 'two ';
public function getParentVar()
{
return parent::getVar();
}
}
$oA = new A();
echo $oA->getVar();
$oB = new B();
echo $oB->getParentVar();
?>
Output:
one two
Isn't that $oB->getParentVar(); should return 'one '? If not, could someone
explain why parent class takes attribute values from child class?