Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4995253
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类:

2008-03-17 15:22:39

__CLASS__ 返回的是调用它的函数所在的类名,而 get_class($this) 返回的是创建对象的类

<?php
class test {
   function whoami() {
     echo "Hello, I'm whoami 1 !
"
;
     echo "Value of __CLASS__ : ".__CLASS__."
"
;
     echo "Value of get_class() : ".get_class($this)."

"
;
   }
}
class test2 extends test {
   function whoami2() {
     echo "Hello, I'm whoami 2 !
"
;
     echo "Value of __CLASS__ : ".__CLASS__."
"
;
     echo "Value of get_class() : ".get_class($this)."

"
;
     parent::whoami(); // call parent whoami() function

   }
}
$test=new test;
$test->whoami();
$test2=new test2;
$test2->whoami();
$test2->whoami2();
?>

输出:
Hello, I'm whoami 1 !
Value of __CLASS__ : test
Value of get_class() : test

Hello, I'm whoami 1 !
Value of __CLASS__ : test
Value of get_class() : test2

Hello, I'm whoami 2 !
Value of __CLASS__ : test2
Value of get_class() : test2

Hello, I'm whoami 1 !
Value of __CLASS__ : test
Value of get_class() : test2

阅读(1802) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~