I am trying to get a result from a chaining method from extended classes below,
class Base
{
protected $id;
public function setId($input) {
$this->id = $input;
return $this;
}
}
class PageChildren extends Base
{
public function getID()
{
return $this->id;
}
}
class Page extends Base
{
public $hasChidren;
public function __construct()
{
$this->hasChidren = new PageChildren();
}
}
$page = new Page();
var_dump($page->setId(10)->hasChidren->getID());
But I get null
instead of 10
. What shall I do to get it right?