Rumah > Artikel > pembangunan bahagian belakang > _unset()这是如何了
__unset()这是怎么了
class Person {<br /> private $name;<br /> private $age;<br /> private $sex;<br /> //2. 构造方法 //作用: 给对象属性初始值<br /> function __construct($name='', $age='0', $sex='男'){ <br /> $this->name=$name;<br /> $this->age=$age;<br /> $this->sex=$sex;<br /> }<br /> private function __set($proName, $proValue){<br /> if($proName == 'age'){<br /> if($proValue<0 || $proValue>100){<br /> echo '设置的年龄不合法';<br /> return;<br /> }else{<br /> $this->$proName=$proValue;<br /> echo $this->age.'<br />';<br /> }<br /> }<br /> }<br /> private function __get($proName){<br /> if($proName == 'age'){<br /> echo ($this->$proName-20).'<br />';<br /> }<br /> }<br /> private function __isset($proName){<br /> if(isset($this->$proName)){<br /> echo $this->$proName.'存在<br />';<br /> return;<br /> }<br /> echo $proName.'不存在<br />';<br /> }<br /> private function __unset($proName){<br /> unset($this->$proName);<br /> }<br /> function say(){<br /> echo 'name........'.$this->name.'|age.........'.$this->age.'|sex..........'.$this->sex.'<br />';<br /> }<br /> function __destruct(){<br /> }<br /> }<br /> $p1 = new Person('yeteng', 26, '男');<br /> $p2 = new Person('yeben', 28, '男');<br /> $p3 = new Person('wenjing', 40, '女');<br /> $p1->age=99; //自动触发__set<br /> $p1->age; //自动触发__get<br /> isset($p1->name);//自动触发__isset<br /><br /> unset($p1->age); //自动触发__unset<br /> $p1->say();