__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
阅读(1855) | 评论(0) | 转发(0) |