(PHP 5 >= 5.3.0)
get_called_class — 后期静态绑定("Late Static Binding")类的名称
说明
string
get_called_class (
void )
获取静态方法调用的类名。
<?php
class foo {
static public function test() {
var_dump(get_called_class());
}
}
class bar extends foo {
}
foo::test();
bar::test();
?>
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"
PHP get_called_class 方法详解
本文介绍了 PHP 中 get_called_class 方法的基本用法及其在后期静态绑定中的作用。通过示例展示了如何利用该方法来获取静态方法被调用时所属的具体类名。
766

被折叠的 条评论
为什么被折叠?



