I got a protected variable in Father
class, the content of this variable will change in Father
class but I need to use this variable in sub classes, i.
You have to invoke the parent constructor.
class Father {
protected $body;
function __construct(){
$this->body = 'test';
}
}
class Child extends Father {
function __construct(){
parent::__construct();
echo $this->body;
}
}
$c = new Father();
$d = new Child();
Reference: http://php.net/manual/en/language.oop5.decon.php