note 33374 added to language.oop
| From: | oran at anonimous dot biu dot ac dot il | Date: | Tue, 24 Jun 2003 10:59:10 +0000 |
| Subject: | note 33374 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50923@lists.php.net to get a copy of this message | ||
The editor's suggestion for using the predefined constant __CLASS__ for interaction between
static functions is incorrect. __CLASS__ gives the name of the class where the method that uses it
is defined, and NOT the name of the extending class that is actually in use.
Therefore, the following code on PHP 4.3.0 prints "baseclass, bla" and not "subclass,
foo":
class baseclass {
function static1() {return "bla";}
function static2() {
return __CLASS__ . ', ' .
call_user_func(array(__CLASS__,'static1'));
}
}
class subclass extends baseclass {
function static1() {return "foo";}
}
print subclass::static2();
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33374
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33374&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33374&report=yes