get_class和get_called_class的区别

get_class () 获取当前调用方法的类名

get_called_class() 获取静态绑定后的类名

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=newB();  
$B->test();  // string'Foo'(length=3)
$B->test2();  // string'B'(length=1)
Foo::test3(); // string'Foo'(length=3) 
Foo::test4(); // string'Foo'(length=3) 
B::test3();  //  string'Foo'(length=3)
B::test4();  //  string'B'(length=1)
点赞(3) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部