之前看过一次,但是忘了static和self的具体区别了,这次在复习一下。
static是PHP5.3之后加进来的,看一下英文的解释:
self refers to the same class whose method the new operation takes place in.
static in PHP 5.3's late static bindings refers to whatever class in the hierarchy which you call the method on.
立即学习“PHP免费学习笔记(深入)”;
之前看过一个文章这个例子很好: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();static:指向调用它的类
还是很容易理解的,下次不能再忘了。
以上就介绍了关于PHP中static和self的区别,包括了static方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号