PHP classes behave themselves strangely?

Alexandr A

New member
Hi. The code below outputs "firstsecond", although it means to output "firstfirst". I though that $a->d() and $a->q->c() are identical calls but it turns out that when calling a method d() from class b the variables have taken from class b.

Why? How I am suppose to take $v from class a instead class b while calling it like that: $a->q->c()?

<?

class a {
public $v;
public $q;

public function __construct ()
{
$this->q=new b();
$this->v="first";
}

public function d () {
echo $this->v;
}

}

class b {
public $v="second";
public function c () {
a::d();
}

}

$a=new a;
$a->d();
$a->q->c();

?>
 
Back
Top