请选择 进入手机版 | 继续访问电脑版
收起左侧

php-get_called_class-获取静态绑定后的类名

[复制链接]

552

主题

569

帖子

1万

积分

管理员

站长

Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20

积分
16427

灌水之王

QQ
发表于 2020-2-5 19:26:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x


get_class (): 获取当前调用方法的类名; get_called_class():获取静态绑定后的类名;


[PHP] 纯文本查看 复制代码

class Foo{
      public function test(){
         var_dump(get_class());
      }
 
      public function test2(){
        var_dump(get_called_class());
      }
 
      public static function test3(){
        var_dump(get_class());
      }
 
      public static function test4(){
        var_dump(get_called_class());
      }
   }
 
   class B extends Foo{
 
   }
 
   $B=new B();
   $B->test();
   $B->test2();
   Foo::test3();
   Foo::test4();
   B::test3();
   B::test4();

结果:
[PHP] 纯文本查看 复制代码
string 'Foo' (length=3)
string 'B' (length=1)
string 'Foo' (length=3)
string 'Foo' (length=3)
string 'Foo' (length=3)
string 'B' (length=1)





上一篇:php-trait__call 魔术方法
下一篇:php-抽象类
QQ:2424004764
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|客户端下载|先锋者IT论坛 ( 湘ICP备16007032号湘公网安备 43030202001052号

GMT+8, 2024-4-18 20:58 , Processed in 0.096998 second(s), 17 queries , File On.

Powered by Discuz! X3.3

© 2017 bbs.fologde.com. Template By Gstudio

快速回复 返回顶部 返回列表