Object Inheritance, get_class() and a static function call
| From: | axel | Date: | Tue, 26 Jul 2005 19:02:05 +0000 |
| Subject: | Object Inheritance, get_class() and a static function call | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-219373@lists.php.net to get a copy of this message | ||
Hello,
following code won't work in the expected way:
class ClassA {
function getClassName() {
return get_class($this); # [1]} } class ClassB extends ClassA { } echo ClassB::getClassName(); this script echoes "Object" instead of "ClassB". but i would like to return the classname of the derived class without writing the method again. this will work: B = new ClassB(); echo ClassB->getClassName(); i tried to use line [2] instead of [1] return get_class(self); # [2] but this only returns an empty string. is there any solution for my problem? i'm using PHP Version 5.0.3 (with Apache 1, Windows XP) greetings axel