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)

相关文章:

  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2021-12-26
  • 2022-02-14
  • 2022-12-23
  • 2021-05-10
  • 2021-11-02
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案