変数をメソッドを保持するjavascriptの機能と同様に、単に値を返すのではなく、PHPクラスの変数を参照するときに関数を実行できますか?インスタンス変数がPHPクラスで参照されているときにメソッドを実行しますか?
class LazyClassTest()
{
protected $_lazyInitializedVar;
public function __construct()
{
/* // How can this call and return runWhenReferrenced() when
// someone refers to it outside of the class:
$class = new LazyClass();
$class->lazy;
// Such that $class->lazy calls $this->runWhenReferrenced each
// time it is referred to via $class->lazy?
*/
$this->lazy = $this->runWhenReferrenced();
}
protected function runWhenReferrenced()
{
if (!$this->_lazyInitializedVar) {
$this->_lazyInitializedVar = 'someValue';
}
return $this->_lazyInitializedVar
}
}
うーん...私たちのすべてがドイツ理解していないので、なぜ英語のマニュアルを共有しませんか? :-) – Rafid
申し訳ありませんが、リンクを修正しました。 – mplappert
これは私が探していたものではありませんが、実際に使用し終わったので、助けてくれました。ありがとう! – cjroth