本文共 686 字,大约阅读时间需要 2 分钟。
"; } function say_b() { echo "'b' - said the " . get_class($this) . ""; } } class derived_class extends base_class{ function say_a() { parent::say_a(); echo "'a' - said the " . __CLASS__ . ""; } function say_b() { parent::say_b(); echo "'b' - said the " . get_class($this) . ""; } }$obj_b = new derived_class();$obj_b->say_a(); echo "";$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()继承父类的代码
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/4096741.html,如需转载请自行联系原作者