Late Static Bindings (PHP 5.3)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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 *


five × 8 =