Re: note 24883 added to keyword.extends

From: Date: Wed, 04 Sep 2002 23:08:41 +0000
Subject: Re: note 24883 added to keyword.extends
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-36125@lists.php.net to get a copy of this message
This is the de expected behaviour when you are overriding a parent's member variable or method. And BTW, it is the inherited changeId() method in B the one you are calling. You might be confusing PHP w/ an OOP language like Java, where classes can define private, protected, etc. vars. No such thing in PHP, although you are welcomed to contribute C code to implement such constructs, go to the php-dev list. Your incorrect note will be removed. --- antonio.afonso@link.pt wrote: > there is a problem with variable "overriding" in a > subclass: > > class A > { > var $id; > > function changeid() > { > $this->id = 0; > } > > } > > class B extends A > { > var $id; > > function B() > { > $this->id = 1; > } > } > > $b = new B(); > > echo "A.id = $b->id &lt;br&gt;"; > $b->changeid(); > echo "A.id = $b->id &lt;br&gt;"; > > this will output: > > A.id = 1 > A.id = 0 > > So, the A::changeid() method is actually changing > the $id variable of B too. Maybe php is treating > the A.id and B.id as the same variable, which is > not! > -- > http://www.php.net/manual/en/keyword.extends.php > http://master.php.net/manage/user-notes.php?action=edit+24883 > http://master.php.net/manage/user-notes.php?action=delete+24883 > http://master.php.net/manage/user-notes.php?action=reject+24883 > > > -- > PHP Notes Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > ===== --- Jesus M. Castagnetto <jmcastagnetto@php.net> __________________________________________________ Do You Yahoo!? Yahoo! Finance - Get real-time stock quotes http://finance.yahoo.com

« previous php.notes (#36125) next »