Reply to Object Inheritance, get_class() and a static function call

Your name:

Reply:


Posted by axel on 10/21/25 11:22

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация