Re: Get name of extending class with static method call (PHP5)
| From: | Derrell dot Lipman at UnwiredUniverse dot com | Date: | Wed, 12 Jan 2005 17:35:24 +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-14361@lists.php.net to get a copy of this message | ||
"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();