Contents

PHP: Late Static Bindings

Contents

New to PHP 5.3.0 will be late static bindings. Currently you can use the self keyword in PHP to access static methods of the current class, the new static keyword allows you to access static methods through the inheritance tree. This example from the PHP website explains best…

Code

<?php
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__;
    }
}
A::test();
B::test();

Output

AB

There are more examples in the PHP manual about Late Static Bindings.