What is the difference between calling get_called_class()
and static::class
inside a static class method?
For example:
class Base
{
public static function foo()
{
return static::class;
}
public static function bar()
{
return get_called_class();
}
}
class Child extends Base {}
echo Base::foo(); // prints 'Base'
echo Base::bar(); // prints 'Base'
echo Child::foo(); // prints 'Child'
echo Child::bar(); // prints 'Child'
It appears to work the same in both cases but there may be some nuances I should be aware of.