Home > Backend Development > PHP Tutorial > Chinese explanation of magic methods in PHP object-oriented_PHP tutorial

Chinese explanation of magic methods in PHP object-oriented_PHP tutorial

WBOY
Release: 2016-07-13 10:37:09
Original
800 people have browsed it

1.__construct()

Instantiated objects are automatically called. __construct is called when __construct and the function with the class name and function name exist at the same time, and the other one is not called.

The function with the class name and function name is the old version of the constructor.

2.__destruct()

Called when deleting an object or when an object operation ends.

3.__call()

The object calls a method. If the method does not exist, call __call this method

4.__get()

Read an object property, if the object property is private it will be called

5.__set()

When assigning a value to an object property, it will be called if the property is private

6.__toString()

Will be called when printing an object.

7.__clone()

Called when cloning an object, such as: $a=new test(); $a1=clone $a;

8.__sleep()

Serialize was called before. If the object is relatively large and you want to delete some things during serialization, you can use it.

9.__wakeup()

Called during Unserialize to do some object initialization work.

10.__isset()

Detects whether an object's attribute exists. It will be called if the detected attribute is private.

11.__unset()

When deleting an object attribute, if the deleted object attribute is private, it will be called

12.__set_state()

Called when var_export is called. Use the return value of __set_state as the return value of var_export.

13.__autoload()

When instantiating an object, if the corresponding class does not exist, this method will be ignored.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736805.htmlTechArticle1.__construct() The instantiated object is automatically called. __construct is called when __construct and the function with the class name and function name exist at the same time, and the other one is not called. Function whose class name is function name...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template