Re: Unexpected behaviuor with __CLASS__
| From: | Torsten Roehr | Date: | Wed, 16 Jun 2004 14:02:48 +0000 |
| Subject: | Re: Unexpected behaviuor with __CLASS__ | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188395@lists.php.net to get a copy of this message | ||
"Robin Vickery" <robinv@gmail.com> wrote in message
news:5cb2dafd040616054983653e5@mail.gmail.com...
> On Wed, 16 Jun 2004 11:49:31 +0200, Torsten Roehr <roehr@zilleon.com>
wrote:
> >
> > Hi list,
> >
> > on RedHat with PHP 4.3.6 the following code produces 'test' - I'm
expecting
> > 'test2':
> >
> > class test {
> > function printClass() {
> > echo __CLASS__;
> > }
> > }
> >
> > class test2 extends test {
> > }
> >
> > test2::printClass();
> >
> > I would like to get/echo the name of the class calling the method - in
my
> > case test2. Any ideas?
>
> If you were using objects rather than class methods you could replace
> __CLASS__ with get_class($this) ...but you're not.
>
> you could use debug_backtrace()
>
> function printClass()
> {
> $details = array_shift(debug_backtrace());
> print $details['class'];
> }
Hi Robin,
thanks! That will be a workaround for my problem. Unfortunately I can't use
get_class() because I need to work with static methods here. I've got a
factory method in my base class for creating objects and I don't want to
pass the name of the class as a parameter.
Thanks and best regards,
Torsten Roehr