Home > Backend Development > PHP Tutorial > PHP中static 跟self的使用区别

PHP中static 跟self的使用区别

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:47:16
Original
947 people have browsed it

PHP中static 和self的使用区别

class A {
??? public static function who() {
??? ??? echo __CLASS__;
??? }
??? public static function test() {
??? ??? self::who();
//??? ??? static::who();
??? }
}
A::test();

class B extends A {
??? public static function who() {
??? ??? echo __CLASS__;
??? }
}
echo B::test();

?

如果使用关键字self运行结果:?? A A

如果使用关键字static运行结果:A B

static:父类访问了子类的静态方法

self: 是类内指针,指向本类,静态方法,属性

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
Latest Issues
Static resource path usage
From 1970-01-01 08:00:00
0
0
0
Course static resources
From 1970-01-01 08:00:00
0
0
0
static variable
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template