get_called_class

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

get_called_class后期静态绑定("Late Static Binding")类的名称

说明

get_called_class(): string

获取静态方法调用的类名。

参数

此函数没有参数。

返回值

返回类的名称。

错误/异常

如果在类外调用 get_called_class(),将抛出 Error。在 PHP 8.0.0 之前,触发 E_WARNING 级别错误。

更新日志

版本说明
8.0.0 类外调用此函数现在将触发 Error。 之前触发 E_WARNING 并且函数返回 false

示例

示例 #1 get_called_class() 的使用

<?php

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

class
bar extends foo {
}

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

?>

以上示例会输出:

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

参见

To Top