note 24883 added to keyword.extends
| From: | antonio dot afonso at link dot pt | Date: | Tue, 03 Sep 2002 20:23:35 +0000 |
| Subject: | note 24883 added to keyword.extends | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-36077@lists.php.net to get a copy of this message | ||
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 <br>";
$b->changeid();
echo "A.id = $b->id <br>";
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