我试图从下面的扩展类的链接方法中获得结果,
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());
但我得到null
而不是10
. 我该怎么做才能让它正确?