作者gpmm (银色)
看板PHP
标题Re: [请益] 由::呼叫时自动产生建构式
时间Tue Apr 17 22:49:31 2012
※ 引述《JYHuang (夏天到了,冷不起来了说)》之铭言:
: 他透过一些判断,当直接呼叫范围运算子时
: 如果没有实体化,会把类别先实体化。
: 只是想试试这个办法能不能运用在目前写的Class上。
好吧…虽然我觉得这已经很 dirty code 了… XD
class Model {
private $bar;
function __construct () {
$this->bar = 'foo';
}
function getbar () {
if (! isset ($this)) {
$m = new Model ();
return $m->getbar ();
}
else
return $this->bar;
}
}
$bar = Model::getbar ();
看看这是不是你要的 :Q
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 175.180.69.185