__unset () Magic Method Delete Private Property
unset () Delete a shared property by using the __unset () Magic method to manipulate the private property
Automatically executes the In-Class __unset () Magic method when the unset () function is executed outside the class
Class HDW {private $name; Private $age; Private $money; Employee pay public $c; function __construct ($name, $age = ", $money) {$this->name = $name; $this->age = $age; $this->money = $money; } function __isset ($var) {$array = array ("name", "Age"); if (In_array ($var, $array)) {echo $var. "attribute exists, his value is:". $this-$var; } elseif (In_array ($var, Array_keys (Get_object_vars ($this)))) {echo "property does not allow external check"; Return } else {echo ' property does not exist '; }} function __unset ($c) {if ($c = = ' age ') {unset ($this, $c); echo "Delete attribute {$c} successfully! "; } else {echo "does not allow deletion of property {$c}"; }} function Get_money () {echo $this->money; }} $lisi = new HDW ("John Doe", 5500),//isset ($lisi->money2222);//echo isset ($_get[' page ')? $_get[' Page ']:1;unset ( $lisi->name);//echo $lisi->get_money ();
__unset () Magic Method Delete a private property within a class