php面向对象中的魔术方法中文说明_PHP

WBOY
Release: 2016-06-01 11:56:29
Original
834 people have browsed it

1.__construct()

实例化对象是被自动调用。当__construct和以类名为函数名的函数 同时存在时调用__construct,另一个不背调用。

类名为函数名的函数为老版的构造函数。

2.__destruct()

当删除一个对象或一个对象操作结束是被调用。

3.__call()

对象调用某个方法。若方法不存在,这调用__call 这个方法

4.__get()

读取一个对象属性,如果对象属性是私有的会调用它

5.__set()

给一个对象属性赋值时如果属性是私有的会调用它

6.__toString()

打印一个对象的时候会被调用。

7.__clone()

克隆对象时被调用,如:$a=new test(); $a1=clone $a;

8.__sleep()

Serialize 之前被调用,若对象比较大,想删减一点东西在序列化可以用它。

9.__wakeup()

Unserialize时被调用,做些对象的初始化工作。

10.__isset()

检测一个对象的属性是否存在如果 检测的属性是私有的时候会被调用。

11.__unset()

删除一个对象属性时如果 删除的对象属性是私有的会被调用

12.__set_state()

调用var_export时,被调用。用__set_state的返回值做为var_export的返回值。

13.__autoload()

实例化一个对象时,如果对应的类不存在,则该方法被掉用。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!