array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'function.get-called-class.php', 1 => 'get_called_class', ), 'up' => array ( 0 => 'ref.classobj.php', 1 => 'Classes/Object Functions', ), 'prev' => array ( 0 => 'function.enum-exists.php', 1 => 'enum_exists', ), 'next' => array ( 0 => 'function.get-class-methods.php', 1 => 'get_class_methods', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/classobj/functions/get-called-class.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
get_called_class — The "Late Static Binding" class name
This function has no parameters.
Returns the class name.
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.
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 .
|
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"