php8.5
Home/ Manual/ classobj / functions/ get_called_class

get_called_class

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

The "Late Static Binding" class name

Description

get_called_class(): string

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

Parameters 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

VersionDescription
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.

Examples

Using get_called_class()

php
<?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:

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

See Also

Source: reference/classobj/functions/get-called-class.xml · from the official PHP manual (php/doc-en)