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');