Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14363 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13652 invoked by uid 1010); 12 Jan 2005 19:05:47 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 13594 invoked by uid 1007); 12 Jan 2005 19:05:46 -0000 Message-ID: <20050112190546.13551.qmail@pb1.pair.com> To: internals@lists.php.net References: <20050112155751.33379.qmail@pb1.pair.com> <20050112173425.GA1234@panix.com> Date: Wed, 12 Jan 2005 20:07:50 +0100 Lines: 48 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Posted-By: 217.86.168.9 Subject: Re: [PHP-DEV] Get name of extending class with static method call (PHP5) From: roehr@zilleon.com ("Torsten Roehr") "Daniel Convissor" 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