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

PHP中static 跟self的使用区别

WBOY
WBOYOriginal
2016-06-13 13:14:15799browse

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: 是类内指针,指向本类,静态方法,属性

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