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]

Reply via email to