What is the Different between self:: and static ?
Different between self:: and static (Late Static Bindings)
Static references to the current class like self:: or __CLASS__ are resolved using the class in which the function belongs, as in where it was defined.
Late static bindings tries to solve that limitation by introducing a keyword that references the class that was initially called at runtime. Basically, a keyword that would allow you to reference B from test() in the previous example. It was decided not to introduce a new keyword but rather use static that was already reserved.
Example: (self::)class A {
   public static function who() {
       echo __CLASS__;
   }
   public static function test() {
       self::who();
   }
}
class B extends A {
   public static function who() {
       echo __CLASS__;
   }
}
B::test();
// Return A
Â
Example: (static::)class A {
   public static function who() {
       echo __CLASS__;
   }
   public static function test() {
       static::who(); // Here comes Late Static Bindings
   }
}
class B extends A {
   public static function who() {
       echo __CLASS__;
   }
}
B::test();
// Return B
Source : http://php.net/manual/en/language.oop5.late-static-bindings.php
Comments