"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();

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

Reply via email to