PHP 让__get方法从新执行

<?php
class A {

public function __get($p) {
	echo "getting $p\r\n";
	if(isset($this->$p)) {
		return $this->$p;
	}

	if($p == 'p1') {
		$this->$p = 456;
	}
	return $this->$p;
	}

}


$a = new A();
var_dump($a->p1);
//$a->p1 = null; //从新获取$a->$p1时,不会触发__get!!
unset($a->p1);//从新获取$a->$p1时,会触发__get
var_dump($a->p1);
相关文章
相关标签/搜索