Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14393 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29139 invoked by uid 1010); 15 Jan 2005 07:30:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86760 invoked from network); 15 Jan 2005 05:34:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jan 2005 05:34:16 -0000 X-Host-Fingerprint: 216.92.131.4 lists.php.net Received: from ([216.92.131.4:9187] helo=lists.php.net) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id AC/39-28860-CF298E14 for ; Fri, 14 Jan 2005 22:50:20 -0500 Received: (qmail 24467 invoked from network); 15 Jan 2005 02:12:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jan 2005 02:12:23 -0000 X-Host-Fingerprint: 216.92.131.4 lists.php.net Received: from ([216.92.131.4:10154] helo=lists.php.net) by pb1.pair.com (ecelerity HEAD (r4105:4106)) with SMTP id 25/F9-28860-58778E14 for ; Fri, 14 Jan 2005 20:53:09 -0500 Received: (qmail 26425 invoked by uid 1007); 14 Jan 2005 17:53:29 -0000 Message-ID: <20050114175328.26383.qmail@lists.php.net> To: internals@lists.php.net References: <20050112155751.33379.qmail@pb1.pair.com> <20050112161637.86918.qmail@pb1.pair.com> <20050112190726.23678.qmail@pb1.pair.com> <41E5790D.2090402@cschneid.com> <41E774CA.8040808@hristov.com> Date: Fri, 14 Jan 2005 14:52:37 +0100 Lines: 57 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.224.226.123 Subject: Re: [PHP-DEV] Re: Get name of extending class with static methodcall (PHP5) From: roehr@zilleon.com ("Torsten Roehr") "Andrey Hristov" wrote in message news:41E774CA.8040808@hristov.com... > Christian Schneider wrote: > > Torsten Roehr wrote: > > > >> Something so straightforward and fundamental should be possible!?! > > > > > > Maybe is isn't as fundamental as you think? I never came across this > > problem in years of PHP programming. But then again I use classes with > > static calls for nothing but separate namespaces :-) > > > > I'm pretty sure there is another (possibly more elegant) solution. This > > is not a flame but a suggestion to rethink the problem you are trying to > > solve. > > > > - Chris > > > Hi Chris, > I have faced this limitation of the languagee when I was trying to simplify > code which uses Singleton and uses to have n-time the code for caching > copied around. Every new class that one subclass has to copy the code. A bit > overwork, isn't it? At the end we agreed on a solution with __CLASS__ in the > extending classes. > > class Foo { > function getInstanceInt($params, $class_name= __CLASS__) { > var_dump($params, $class_name); > /*...*/ > } > } > class Bar extends Foo { > function getInstance() { > Foo::getInstanceInt(func_get_args(), __CLASS__); > } > } > $a= Bar::getInstance(1,2,3); > > So the getInstance() in the subclasses is quite simple. One also > may declare argument names. Here I haven't done that for simplicity. > > Regards, > Andrey Hi Andrey, thanks for your posts. It seems that this is the only viable solution - passing the class name in as a parameter. Thanks and best regards, Torsten Roehr