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)
posted @ 2019-05-12 17:44  牛奔  阅读(916)  评论(0编辑  收藏  举报