Home  >  Article  >  Backend Development  >  php面向对象之类的静态成员

php面向对象之类的静态成员

WBOY
WBOYOriginal
2016-06-23 13:34:14972browse

类的静态成员使用static关键字来标识。
静态方法非常类似于全局函数。
类的静态属性非常类似于函数的全局变量。
类的静态成员与一般的类成员不同: 静态成员与对象的实例无关,只与类本身有关. 他们用来实现类要封装的功能和数据,但不包括特定对象的功能和数据。
在类中不能使用$this来引用静态成员属性和方法。
类中的静态成员是不需要对象而使用类名来直接访问。
在类中,使用“self::"或者"类名::"来访问其它静态成员。
在类的外部使用"类名 :: 类成员"形式静态地访问某个成员,不仅省略掉实例化类的代码,而且效率会更高。

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