0

这样的事情可能吗?

<?
class A
{
   public static function fun()
   {
      var_dump(get_class(child)); //bool(false) //should return B
   }
}
class B extends A
{
   public static function fun()
   {
      parent::fun();
   }
}

B::fun();
?>
4

2 回答 2

2

自 PHP 5.3 起,有用get_called_class()于此目的:

echo get_called_class(); // yields "B"
于 2012-08-11T22:09:36.967 回答
2
<?php
class B extends A
{
   public static function fun()
   {
      parent::fun();
   }
}
class A
{
   public static function fun()
   {
      var_dump(get_called_class());
   }
}

B::fun();

http://php.net/manual/en/function.get-call-class.php

于 2012-08-11T22:09:45.917 回答