get_called_class()

get_called_class() — The "Late Static Binding" class name.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.3.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Gets the name of the class the static method is called in.

Signature

get_called_class(): string

Parameters

This function takes no parameters.

Return value

Returns the class name.

Example

A runnable snippet:

class foo { static public function test() { var_dump(get_called_class()); } } class bar extends foo { } foo::test(); bar::test();

Output:

string(3) "foo" string(3) "bar"

Changelog

VersionChange
8.0.0Calling this function from outside a class, will now throw an Error. Previously, an E_WARNING was raised and the function returned false.

See also

get_parent_class(), get_class(), is_subclass_of()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page get_called_class() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.