<?php
class dog {
protected $name='小黑';
private $age='4years';
public $color='wide';
public function __get($a){
echo 'you are want see my ',$a,'!<br />';
}
public function __unset($a){
echo '当unset:',$a,'属性不存在时或被保护时,我被触发了!';
}
}
$one=new dog();
print_r ($one);
echo '<br />';
$one->name;
class dog {
protected $name='小黑';
private $age='4years';
public $color='wide';
public function __get($a){
echo 'you are want see my ',$a,'!<br />';
}
public function __unset($a){
echo '当unset:',$a,'属性不存在时或被保护时,我被触发了!';
}
}
$one=new dog();
print_r ($one);
echo '<br />';
$one->name;
unset($one->name);//这个属性在类中是不存在或被保护且私有的时候,它会触发类中的unset方法。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
运行代码
dog Object ( [name:protected] => 小黑 [age:dog:private] => 4years [color] => wide )
you are want see my name!
当unset:name属性不存在时或被保护时,我被触发了!