illustrate
1. Private member attributes can be obtained outside the object. __get() not only obtains the private member variables of the current class, but can also perform other operations in this method.
For example, instantiate another class and obtain an object of another class.
2. If the member properties are not encapsulated as private, the object itself will not automatically call this method.
Example
<?php class autofelix { private $name = 'autofelix'; public function __get($name) { if(in_array($name, ['name', 'age'])) { echo $this->name; } else { echo 'Not everything can be accessed~'; } } } $a = new autofelix(); $a->name; //Output: autofelix
The above is the __get method in PHP to obtain member attributes. I hope it will be helpful to everyone.