Hi,
one may use __CLASS__ instead of get_class().


Andrey

Torsten Roehr wrote:
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
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" <[EMAIL PROTECTED]> 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


-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to