Home > Article > Backend Development > PHP magic method (introduction), php magic method introduction_PHP tutorial
public void _set(string $name,mixed $value)
public mixed _get(string $name)
public bool _isset(string $name)
public void _unset(string $name)
public mixed _call(string $name,array $arguments)
These methods work as follows:
_set(string $name,mixed $value): Called when the object assigns a value to an undefined or invisible attribute. The parameter name is the attribute that needs to be assigned, and the value is the value that needs to be assigned to the attribute.
_get(string $name): Called when the object accesses undefined or invisible attributes. The parameter name is the name of the attribute that needs to be accessed.
_isset(string $name): Called when isset() is used for undefined or invisible attributes. The parameter name is the attribute name.
_unset(string $name): Called when unset() is used on undefined or invisible attributes. The parameter name is the attribute name.
_call(string $name, array $arguments): Called when an object calls an undefined or invisible method. The parameter name is the method name, and the parameter arguments is an array of parameters to be passed to the method.
Note: The function of these pattern methods is to intercept operations that access non-existent object members, and then respond accordingly, and these methods must be decorated with public.