note 72110 added to language.oop.constructor

From: Date: Wed, 03 Jan 2007 09:23:18 +0000
Subject: note 72110 added to language.oop.constructor
Groups: php.notes 
Request: Send a blank email to php-notes+get-121228@lists.php.net to get a copy of this message
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? ---- Server IP: 83.64.128.68 Probable Submitter: 193.22.91.42 ---- Manual Page -- http://www.php.net/manual/en/language.oop.constructor.php Edit -- https://master.php.net/note/edit/72110 Del: integrated -- https://master.php.net/note/delete/72110/integrated Del: useless -- https://master.php.net/note/delete/72110/useless Del: bad code -- https://master.php.net/note/delete/72110/bad+code Del: spam -- https://master.php.net/note/delete/72110/spam Del: non-english -- https://master.php.net/note/delete/72110/non-english Del: in docs -- https://master.php.net/note/delete/72110/in+docs Del: other reasons-- https://master.php.net/note/delete/72110 Reject -- https://master.php.net/note/reject/72110 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121228) next »