Reputation: 76298
abstract class Ghost {
protected static $var = 'I\'m a ghost';
final public static function __callStatic($method, $args = array()) {
echo self::$var;
}
}
class Person extends Ghost {
protected static $var = 'I\'m a person';
}
The call of Person::whatever()
will print: I'm a ghost
.
Why?
Upvotes: 2
Views: 3320
Reputation: 31
"self" is used by Current class, if you want get child static property, use "static" as :
final public static function __callStatic($method, $args = array()) {
echo **static**::$var;
}
Upvotes: 3
Reputation: 21249
You're looking for something called Late Static Binding, which requires PHP 5.3+
Upvotes: 5