<?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);