Late Static Bindings (PHP 5.3)

// Limitation of Self:: in PHP 5.2 
// before Late Static Binding PHP 5.3
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(); // This will output: A

// Late Static Binding in PHP 5.3
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // Late Static Bindings
    }
}

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}

B::test(); // This will output: B

Leave a Reply

Your email address will not be published. Required fields are marked *


one × = 1