You are here: Re: [PHP] Object Inheritance, get_class() and a static function call « PHP « IT news, forums, messages
Re: [PHP] Object Inheritance, get_class() and a static function call

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

Hello Richard,

thanks for for your answer.

> a> class ClassA {
> a> function getClassName() {
> a> return get_class($this); # [1]
> a> }
> a> }
> a> class ClassB extends ClassA { }
> a> echo ClassB::getClassName();
>
> a> this script echoes "Object" instead of "ClassB". but i would like to
> a> return the classname of the derived class without writing the method again.
>
> "The double colon, is a token that allows access to static, constant,
> and overridden members or methods of a class."
>
> Of which none of yours are (at least not in the code posted)

Sure! It's the first one: i'm calling a method of the class without
instantiaton. it works even though the method isn't declared static.
maybe this is the fault!?


class ClassA {
public static function getClassName() {
return get_class($this); // [1]
// or [2] return get_class(self);
// or [3] return __CLASS__;
}
}
class ClassB extends ClassA { }
echo ClassB::getClassName();

> Wouldn't get_parent_class() work in this situation?

No, because there is no parent class of ClassA and im searching for the
name of the derived class.

Maybe i will found the solution on
http://php.belnet.be/manual/en/language.oop5.static.php
Still reading...

Best regards,
Axel P.

 

Navigation:

[Reply to this 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

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