__unset () Magic Method Delete a private property within a class

Source: Internet
Author: User

__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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.