Slowly long search night, the moon hanging
__get ()-__get () is called when the value of the Inaccessible property is read
__set ()-__set () is called when a value is assigned to an unreachable property
<?php/** * Clear understanding of __get () __set () */class Example { //public properties $public = ' pub '; Protected-the attribute in the subclass can be protected $protected = ' Pro '; Private-only This class uses this property private $private = ' pri '; The __get () method is loaded automatically when a property in the Access object does not exist or is not a public attribute __get ($name) { return ' calls the __get () method: '. $name; } When assigning a value to an object's property, the __set () method is loaded automatically if the property does not exist or is not a public property () __set ($name, $value) { echo "\nname:". $ Name. ', Value: '. $value. ' \ n "; }} $example = new Example;echo ' <pre> '; Echo $example->public. " \ n "; Echo $example->protected." \ n "; Echo $example->private." \ n "; Echo $example->other." \ n "; Echo '
The results are as follows:
Pub calls the __get () method: protected Call the __get () method: Private Call the __get () method: Othername: protected, Value:tecname:private, value:vatname:other, value: Public Property: Lic
PHP Magic Method __get __set (ii)