Home>Article>Backend Development> What are the magic methods in php7
php7 magic methods include: 1. "__contract" method; 2. "__destruct" method; 3. "__set" method; 4. "__get" method; 5. "__call" method; 6. "__callStatic" "method; 7. "__toString" method and so on.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
What are the magic methods in php7?
A magic method is a special method that overrides PHP's default actions when performing certain operations on an object.
PHP reserves all method names starting with __. Therefore, the use of such method names is not recommended unless overriding PHP's behavior.
php7 magic methods are:
__contract: Triggered when a class is instantiated
__destruct: Triggered when an instance object is destroyed
__set(string $name, mixed $value): Triggered when setting an inaccessible member attribute
__get(string $name): Triggered when getting an inaccessible member attribute
__call($name,$arguments): Triggered when accessing an inaccessible member method
__callStatic($name,$arguments): Triggered when accessing an inaccessible member static method
__toString: Triggered when an object instance is treated as a string
__clone: Triggered when creating a new object
__invoke: Triggered when the object is called as a function
__sleep: Triggered when data processing of an object does not require saving of all data, such as: serialize() serialization
__wakeup: When unserialize(), it will first check whether there is __wakeup Method
__unset(string $name): Triggered when an inaccessible object property is unset
__isset(string $name): Triggered when an inaccessible object property is isset, empty Trigger
__debugInfo: Triggered when an object is var_dump
__set_state: Triggered when an object is var_export
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of What are the magic methods in php7. For more information, please follow other related articles on the PHP Chinese website!