update page now

Voting

: min(four, eight)?
(Example: nine)

The Note You're Voting On

MagicalTux at FF.ST
21 years ago
Note that the constant __CLASS__ is different from get_class($this) :
<?
 class test {
 function whoami() {
 echo "Hello, I'm whoami 1 !\r\n";
 echo "Value of __CLASS__ : ".__CLASS__."\r\n";
 echo "Value of get_class() : ".get_class($this)."\r\n\r\n";
 }
 }
 class test2 extends test {
 function whoami2() {
 echo "Hello, I'm whoami 2 !\r\n";
 echo "Value of __CLASS__ : ".__CLASS__."\r\n";
 echo "Value of get_class() : ".get_class($this)."\r\n\r\n";
 parent::whoami(); // call parent whoami() function
 }
 }
 $test=new test;
 $test->whoami();
 $test2=new test2;
 $test2->whoami();
 $test2->whoami2();
?>
The output is :
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
In fact, __CLASS__ returns the name of the class the function is in and get_class($this) returns the name of the class which was created.

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /