I'm trying to do something like this but i don't succeed.
abstract class Animal
{
abstract static function getName();
static function sayName() { echo self::getName(); }
}
thanks!
I'm trying to do something like this but i don't succeed.
abstract class Animal
{
abstract static function getName();
static function sayName() { echo self::getName(); }
}
thanks!
You have two problems:
It would have been nice if you'd have given a hint as to how you "don't succeed", but I suppose you're stumbling across static bindings and need to use late static bindings introduced in PHP 5.3.
My guess is maybe you are trying to instantiate an object from that class.
You can't. It is an abstract
class. Subclass it, and then instantiate that.
That will not succeed- you cannot have an abstract static function. See the accepted answer Why does PHP 5.2+ disallow abstract static class methods? for details on why.