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

发表日期:2021-07-01 08:57:11 | 来源: | | 浏览(796) 分类:类/对象 函数

get_called_class

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

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

说明

get_called_class(): string

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

返回值

返回类的名称,如果不是在类中调用则返回 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"

参见

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。