search
Homephp教程php手册php面向对象中的魔术方法中文说明

这篇文章主要介绍了php面向对象中的魔术方法中文说明,明白这些方法才好写面向对象程序,需要的朋友可以参考下

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()

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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),