18/1/10

Simulate static binding on PHP < 5.3




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


?>

15/1/10

parsekit

class A { const C = 'A'; const D = self::C; }
class B extends A { const C = 'B'; }
echo B::D;

-->

B

Debe hacer un mix sin llegar a ejecutar.