Home  >  Article  >  Backend Development  >  PHP’s magic methods (introduction)

PHP’s magic methods (introduction)

WBOY
WBOYOriginal
2016-08-08 09:25:00889browse

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 for 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 purpose 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.

The above has introduced the magic method of PHP (introduction), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php folder operationsNext article:php folder operations