In PHP, if a static attribute is defined in the parent class, it cannot be overridden in a child class. But I\'m wondering if there\'s any way around this.
I\'m try
The forthcoming PHP 5.3.0 release includes late static binding, which might help. Using this feature you could use a static variable inside a static method, and let the late static binding take care of finding the "right" method.
class Foo {
public static function getDefault() {
static $default = 'DEFAULT';
return $default;
}
public static function doSomething ($param) {
$default=static::getDefault(); // here is the late static binding
$param = ($param === FALSE) ? $default : $param;
return $param;
}
}
class Bar extends Foo {
public static function getDefault() {
static $default = 'NEW DEFAULT FOR CHILD CLASS';
return $default;
}
}