__get () __set () __isset () __unset
__call __callstatic
__call is called automatically when a method is called that is not visible (does not exist or does not have permissions).
The Say method __call ("Say", Array (->say)) does not exist in the $lisi.
__get () is used to get the property value of a private member, with a parameter that passes in the property name of the private member you want to get, and returns the obtained value. This method does not need to be called by hand, it only needs to be encapsulated in the class. If the member property is not encapsulated as private, the object itself does not automatically call this method. The following code
The __get () method is used to get the private property
Class tian{
Private $age = 18;
Public Function __get ($property _name)
{
if (Isset ($this-$property _name)) {
Return ($this, $property _name);
}
}
}
$a =new Tian ();
Echo $a->age;
If the private property to be called exists, the value passed to the private property is returned, otherwise it is empty $a=new Tian (); the $a->age; here gets 18, through the __get () Magic method, so that the private property can be called outside the class. __set () assigns a value to a private property, has two parameters, one parameter is the name of the private property, the second parameter is the value to assign to the private property, there is no return value, nor does it need to be called manually, and is encapsulated in the class. For example, the following code
Class tian{
Private $age = 18;
Public Function __get ($property _name)
{
if (Isset ($this-$property _name)) {
Return ($this, $property _name);
}
}
Public function __set ($a, $v) {
echo $this $a;
}
}
$a =new Tian ();
echo $a->name= "big idiot";
If the member property is not private, it is not called to the function.
PHP Magic Method Learning Notes