PHP: Simulate late static binding in PHP < 5.3

PHP: Simular static binding en PHP < 5.3

18 Jan 2010

class A {  
    const CONSTANT = 'A';  

    function __construct() {  
        echo constant(get_class($this) . '::CONSTANT');  
        // echo self::CONSTANT; // No static. Would output AA instead of AB.  
        // echo static::CONSTANT; // PHP >= 5.3  
    }  
}  

class B extends A {  
    const CONSTANT = 'B';  
}  

ob_start();  
$a = new A;  
$b = new B;  
var_dump(ob_get_clean() == 'AB');