We have a code
class ParentClass {
public static function getName() {
return get_class(self);
}
}
class ChildClass extends ParentClass {
}
echo ParentClass::getName(); # => 'ParentClass'
echo ChildClass::getName(); # => 'ParentClass'
if I use get_class($this) there is the same result. Also for self::$this, static::$this etc
Any way to get child class name without adding methods to child class for this?
You'll have to use get_called_class
, which binds late. Only available since PHP 5.3 though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With