Object Inheritance, get_class() and a static function call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux