Shoe
Shoe

Reputation: 76298

Abstract static property cannot be overwritten?

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

Answers (2)

Ashen
Ashen

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

Ben
Ben

Reputation: 21249

You're looking for something called Late Static Binding, which requires PHP 5.3+

Upvotes: 5

Related Questions