※ 引述《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