在php 5中,提供了构造函数,析构函数,对象克隆的方法,重载方法等,
1、构造函数__construct
如果在类申明中__construct函数,将被当成一个构造函数并且在对象建立时被执行,但在php4中,构造函数的名称与类名相同就是构造函数哦,这一点有一些不同。
2、析构函数__destruct
如果在php类中申明了,在对象被销毁时调用__destruct函数
下面来看个实例
代码如下 | 复制代码 |
class Session { public function __construct() { echo '构造函数执行'; } public function __destruct() { echo '析构函数执行'; } } $Obj = new Session; unset($Obj);//删除对象, __destruct()会被调用的 //输出 //构造函数执行 /析构函数执行 ?> |
上面在使用new创建对象时就执行了__construct,对象结束时就执行了__destruct()
3、__clone()克隆函数
代码如下 | 复制代码 |
class Session |
4 现在来看关于重载函数__get ,__set,__call函数
代码如下 | 复制代码 |
class Session |
申明本站原创文章转载注明来源于www.111cn.net

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft