php - How do late static bindings work in this scenario? -
the following code outputs 'x set in class a', how make output 'x set in class b' without changing class b?
<?php class { public static $x = 'x set in class a'; public static function getx() { return self::$x; } } class b extends { public static $x = 'x set in class b'; } echo b::getx();
self always refers class, defined. looking "late static binding" (as suggest, dont use). static keyword within code block refers "actual" class, means: either called class (xy::method()), or class of called object ($x->method()).
return static::$x; the static keyword @ property declaration has nothing to lsb. common declartion class properties.
note, lsb not available in php<5.3
Comments
Post a Comment