note 24883 rejected from keyword.extends by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Wed, 04 Sep 2002 23:08:51 +0000 |
| Subject: | note 24883 rejected from keyword.extends by jmcastagnetto | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-36126@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!