Home  >  Article  >  Backend Development  >  PHP magic method (introduction), php magic method introduction_PHP tutorial

PHP magic method (introduction), php magic method introduction_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:55:14888browse

PHP’s magic method (introduction), introduction to php magic method

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/993266.htmlTechArticlePHP’s magic method (introduction), introduction to php magic method public void _set(string $name,mixed $value) public mixed _get(string $name) public bool _isset(string $name) public void _uns...
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