Re: Get name of extending class with static method call (PHP5)
| From: | Torsten Roehr | Date: | Wed, 12 Jan 2005 19:07:50 +0000 |
| Subject: | Re: Get name of extending class with static method call (PHP5) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-14363@lists.php.net to get a copy of this message | ||
"Daniel Convissor" <danielc@analysisandsolutions.com> wrote in message
news:20050112173425.GA1234@panix.com...
> 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