Late Static Bindings' usage

Posted on February 6, 2010, 1:57 pm UTC anonymously (about 1 year ago)

Code (highlighted for PHP)

  1. <?php
  2. class A {
  3.     public static function who() {
  4.         echo __CLASS__;
  5.     }
  6.     public static function test() {
  7.         static::who(); // Here comes Late Static Bindings
  8.     }
  9. }
  10.  
  11. class B extends A {
  12.     public static function who() {
  13.         echo __CLASS__;
  14.     }
  15. }
  16.  
  17. B::test();
  18. ?>
  19.