get_called_class

(PHP 5 >= 5.3.0, PHP 7)
the "Late Static Binding" class name
string get_called_class ( void )

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

Returns:

Returns the class name. Returns FALSE if called from outside a class.

Examples:
Using get_called_class()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?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() -

doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.