I just want clarity of $this
behaviour in PHP. From below program I want to know how can refer $this in class B to class A members, also on same time how can I use $this to refer the class B scope.
<?php //php 7.0.8
class A{
public $name="test";
public function func1(){
echo $this->name="classAFunc";
}
}
class B extends A {
public $name="classB";
public function func2(){
echo $this->name ;
}
}
$test = new B();
echo $test->name; // classB
echo $test->func1();//classAFunc
echo $test->func2();//classAFunc //I want this should output classB
?>
If I am going somewhere wrong please point it out. you refer here to play around : run this program