get_called_class

The "Late Static Binding" class name

Description

string get_called_class()

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

Parameters

This function has no parameters.

Return Values

Returns the class name.

Errors/Exceptions

If get_called_class is called from outside a class, an Error is thrown. Prior to PHP 8.0.0, an E_WARNING level error was raised.

Changelog

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

Examples

Example #1 Using get_called_class

<?php

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

class bar extends foo {
}

foo::test();
bar::test();

?>

The above example will output:

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

See Also

  • get_parent_class
  • get_class
  • is_subclass_of