<?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);
时间: 2024-10-18 13:29:03