1,__construct (), __destruct (), __call (), __callstatic (), __get (), __set (), __isset (), __unset (), __sleep (), __ Methods such as wakeup (), __tostring (), __invoke (), __set_state (), __clone (), and __debuginfo () are called " Magic Methods" (Magic methods) in PHP. You cannot use these method names when naming your own class methods, unless you want to use their magic features.
2. Precautions
PHP retains all class methods that begin with __ (two underscores) as a magic method. Therefore, in addition to the above magic method when defining a class method, it is recommended that you do not prefix __.
3, __get and __set
__get:
__get Magic method, which is automatically called when external access to properties in the class cannot be directly accessed
The Magic method has its default definition format and cannot be changed arbitrarily.
The Magic method cannot be added static modifier, out of the callstatic
__get Magic method must have a return value
__set:
__set Magic Method, which is called automatically when assigning a value to a property that cannot be directly accessed in a class
Property_exists detects whether a class or object contains a property of the specified name
4 , __call Magic Method:
When an inaccessible method is called in an object, __call () is called.
Method_exists A function method that determines whether a class contains a specified name
PHP Magic Method