Hello! > Is there something I don't understand ? Yes.
According OOP concepts, derived class inherits all functionality and data from the base. So, if you have $shared variable in the base class, your derived class will have it automatically. But PHP allows you to declare this variable once again in the derived class. In C++ you will get comilation error in this case. Best regards, Andrew Kirilenko. > -----Original Message----- > From: Alain Dresse [mailto:[EMAIL PROTECTED]] > Sent: Saturday, October 27, 2001 10:12 PM > To: [EMAIL PROTECTED] > Subject: [PHP] overloading variables in child classes > > > Hi all, > > I am a bit puzzled by the way PHP treates variables that have the > same name > in a base class and a child class. > It seems to me that if a child class and its parent both have a variable > with the same name, then they should be different variables. Instead, the > example below indicates that they is only one variable : > ---- > class base { > var $shared; > function base() {$this->shared = "base";} > function test() {echo("\$shared in base : " . $this->shared . > "<br>\n");} > } > > class child extends base { > var $shared; > function child(){$this->base(); $this->shared = "child";} > function test() { > echo ("\$shared in child : " . $this->shared . "<br>\n"); > parent::test(); > } > } > > $the_child = new child(); > $the_child->test(); > ---- > > I would have expected the output to be > $shared in child : child > $shared in base : base > > instead I have > $shared in child : child > $shared in base : child > > Is there something I don't understand ? > > Regards, > Alain Dresse > [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]