首页 > Web开发 > 详细

php get_called_class()函数与get_class函数的区别

时间:2017-12-13 01:43:19      阅读:227      评论:0      收藏:0      [点我收藏+]

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=new B();
   $B->test();
   $B->test2();
   Foo::test3();
   Foo::test4();
   B::test3();
   B::test4();

输出结果:

string ‘Foo‘ (length=3)
string ‘B‘ (length=1)
string ‘Foo‘ (length=3)
string ‘Foo‘ (length=3)
string ‘Foo‘ (length=3)
string ‘B‘ (length=1)

 

 

转:http://blog.csdn.net/tashanhongye/article/details/48159771

参:http://php.net/manual/zh/function.get-called-class.php

 

 

 

 

php get_called_class()函数与get_class函数的区别

原文:http://www.cnblogs.com/fps2tao/p/8030168.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!