之前看过一次,但是忘了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.
之前看过一个文章这个例子很好: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教程有兴趣的朋友有所帮助。