PHP get_called_class() Function
The PHP get_called_class() function is used to get the name of the class where the static method is called.
Syntax
get_called_class()
Parameters
No parameter is required.
Return Value
Returns the class name. Returns false if called from outside a class.
Example: get_called_class() example
The example below shows the usage of get_called_class() function.
<?php class foo { public $message = "Hello World!"; static public function test() { var_dump(get_called_class()); } } class bar extends foo { } foo::test(); bar::test(); ?>
The output of the above code will be similar to:
string(3) "foo" string(3) "bar"
❮ PHP Classes/Objects Reference