Bel*_*sen 1 php static-methods dynamic-binding
class A
{
static function get_name_derived_class()
{
//This function must return the name of the real class
//Is it possible without insert a methon in B class?
{
}
class B extends A
{
}
B::test()
Run Code Online (Sandbox Code Playgroud)
我希望在基类中有一个静态方法,它返回真实(派生)类的名称,而不插入特定的方法.可能吗?感谢名单
<?php
class A
{
static function test()
{
return get_called_class();
}
}
class B extends A
{
}
echo B::test();
Run Code Online (Sandbox Code Playgroud)
需要PHP> = 5.3.0.请参阅PHP的Late Static Bindings手册条目
| 归档时间: |
|
| 查看次数: |
1099 次 |
| 最近记录: |