echo System\Core\Request::factory()->execute();
首先调用factory(),然后调用constructor,最后调用execute()。它当然按预期工作。
请求类包含几个非静态属性。我将它们全部设置在工厂方法中。像这样:
public static function factory()
{
if(! Request::$initial)
{
$request = Request::$initial = Request::$current = new Request();
$request->foo = 'bar';
}
else
{
Request::$current = $request = new Request();
$request->foo = 'aaa';
}
return Request::$current;
}
接下来是构造函数:
public function __construct()
{
echo $this->foo; // displays empty string
echo Request::$current->foo; // trying to get property of non-object
}
到底是怎么回事?