변수를 메서드를 보유하는 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