class A{
public $val = 10;
public function method1(){
$m2 = new B();
return $m2->method2();
}
}
class B extends A{
public function method2(){
return $this->val + 1;
}
}
$a = new A();
echo $a->method1();
class A{
public $val = 10;
public function method1(){
$m2 = new B($this);
return $m2->method2();
}
}
class B {
public function __construct($obj) {$this->obj = $obj;}
public function method2(){
return $this->obj->val + 1;
}
}
$a = new A();
echo $a->method1();