"Daniel Convissor" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Torsten:
>
> On Wed, Jan 12, 2005 at 04:58:20PM +0100, Torsten Roehr wrote:
>
> > How can I get the name of the extending class that invoked the method in
> > drive()?
>
> class Car {
> function drive($child) {
> echo "parent driven in a $child\n";
> }
> }
>
> class Porsche extends Car {
> function drive() {
> parent::drive(get_class());
> }
> }
>
> Porsche::drive();
>
> --Dan
Hi Dan,
thanks for your answer. I know about this solution - but it requires the
definition of drive() in *every* subclass. An alternative would be passing
in the class name as a parameter:
class Car {
function drive($className) {
echo 'parent driven in a $className';
}
}
class Porsche extends Car {
}
Porsche::drive('Porsche');
But this seems kind of stupid, doesn't it?
Best regards, Torsten Roehr
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php