__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()继承父类的代码



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/4096741.html,如需转载请自行联系原作者


相关文章
|
27天前
with class of same name
with class of same name
9 0
|
22天前
Class 的讲解
Class 的讲解
11 1
|
5月前
Class下的getEnumConstants
Class下的getEnumConstants
37 0
class CSplitterWnd :public CSplitterWnd
class CSplitterWnd :public CSplitterWnd
57 0
|
JavaScript 程序员
Class-总结class的基本用法和两个注意点
一、注意点一:class关键字区间使用 二、注意点二:Class关键字内部函数
DHL
|
JSON 安全 算法
value class 完全代替 typealias?
这篇文章将会从 类型安全 、 占用内存 、执行效率 、使用场景 这几个角度来分析 value class ,通过这篇文章,你将学习到以下内容。
DHL
176 0
value class 完全代替 typealias?
|
Apache
class7
搭建lamp
162 0
|
关系型数据库 MySQL Linux
class6
快速搭建LAMP坏境
303 0
class4
安装putty工具远程连接ECS服务器
165 0