search
Homephp教程php手册在动态网页技术PHP5中类(CLASS)的新特征

php5新添加了好多的新函数和特征,但是在目前最新的chm的手册中都没有体现,要到在线的手册中查找,烦啊!

废话不多说了,来看看php5中全新的class对比php2的class有什么新的特征。

1/ 加了访问权限的控制:使用private/public/protected的特征

2/ 加入了接口和抽象类的概念,interface/abstract,可惜的是类的继承还是树形的单继承。

3/ 可以定义final 函数,不能在父类中覆盖这个函数

4/ 终于可以在类中定义 静态的变量,在php中只能在函数中定义,static $aa = nulll;,另外还提供了 const 方法const mystatic = 'aaaaaa';

5/ 新提供了一个self内部方法 echo self::mystatic;

6/ 加入了如下的内部特征

__construct()   初始化

__destruct();   卸载

__get();          组织返回类中的某些变量值。

__set();          组织给类中的某些变量值赋值。

__call();         调用不存在的类的函数的时候得处理方法

__clone();        copy对象用

__sleep();        序列化的时候用

__weekup();      反序列的时候用

7/ 默认的object的赋值采用了应用的方式,如:

$object2 = $object1

$object2 得到的是$object1的引用,不是在内存中copy副本

8/ 提供了 reflection API ,主要用来显示class/function 本省的结构和统计信息,这个是一个全新的东西,很难说清楚,(虽然很强大,但是我个人还是没有找到“这位英雄可以用武的地方”)

9/ 对class对象提供了一个枚举的功能,可以用for循环来处理对象中的全局的变量。

10/ 提供了一个__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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

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

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function