Re: Get name of extending class with static method call(PHP5)

From: Date: Fri, 14 Jan 2005 07:15:30 +0000
Subject: Re: Get name of extending class with static method call(PHP5)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-14385@lists.php.net to get a copy of this message
Hi, one may use __CLASS__ instead of get_class(). Andrey Torsten Roehr wrote:
-----Original Message----- From: Derrell.Lipman@UnwiredUniverse.com [mailto:Derrell.Lipman@UnwiredUniverse.com] Sent: Wednesday, January 12, 2005 6:35 PM To: Torsten Roehr Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Get name of extending class with static method call(PHP5) "Torsten Roehr" <roehr@zilleon.com> writes:
Hi devs, after a long discussion on php-general [1], searching the archives and trying every proposed solution without success I'm asking for
your help to
solve the following problem: class Car { function drive() {
       // I need the name of the calling class here
       // in my case it should be 'Porsche'
} } class Porsche extends Car { } Porsche::drive();
You're previous thread says that you want drive() to be static, but you're not declaring it static. If it needn't be static, then you can do this: class Car { function drive() {
       echo get_class($this) . "\n";
} } class Porsche extends Car { } $carType = new Porsche(); $carType->drive();
Hi Derrell, you are right, but I just forgot to declare it static. Unfortunately this doesn't change the situation - I still need it as a static call and therefore cannot use get_class(). Best regards, Torsten Roehr


« previous php.internals (#14385) next »