I know you can use get_class($this) normally but I need to get the name of the class in a static function where the object hasn't been instantiated.
See the following code:
class ExampleClass
{
static function getClassName()
{
echo get_class($this); // doesn't work unless the object is instantiated.
}
}
$test1 = new ExampleClass();
$test1->getClassName(); // works
ExampleClass::getClassName(); // doesn't work
I think you're looking for the get_called_class() function, if you wish to get the class name from a static method.
See get_called_class documentation for more information.
I figured out you can use __CLASS__ to get the class name. Example:
class ExampleClass
{
static function getClassName()
{
echo __CLASS__;
}
}
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