__CLASS__

<?php

class base_class
{
     function say_a()
     {
         echo "'a' - said the " . __CLASS__ . "<br/>";
     }

     function say_b()
     {
         echo "'b' - said the " . get_class($this) . "<br/>";
     }

 }

 class derived_class extends base_class
{
     function say_a()
     {
         parent::say_a();
         echo "'a' - said the " . __CLASS__ . "<br/>";
     }

     function say_b()
     {
         parent::say_b();
         echo "'b' - said the " . get_class($this) . "<br/>";
     }
 }

$obj_b = new derived_class();

$obj_b->say_a();
 echo "<br/>";
$obj_b->say_b();

?>

执行结果:

'a' - said the base_class
'a' - said the derived_class

'b' - said the derived_class
'b' - said the derived_class


 

tips:

1.__CLASS__获取的是原汁原味的类名

2.parent()继承父类的代码

原文地址:https://www.cnblogs.com/jiqing9006/p/4096741.html