Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:14386 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50665 invoked by uid 1010); 14 Jan 2005 07:26:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 50506 invoked from network); 14 Jan 2005 07:26:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2005 07:26:35 -0000 X-Host-Fingerprint: 80.168.8.116 iko.gotobg.net Linux 2.4/2.6 Received: from ([80.168.8.116:40222] helo=iko.gotobg.net) by pb1.pair.com (ecelerity HEAD (r4059)) with SMTP id 5C/41-22851-32477E14 for ; Fri, 14 Jan 2005 02:26:27 -0500 Received: from pd95e995c.dip.t-dialin.net ([217.94.153.92] helo=[192.168.0.41]) by iko.gotobg.net with esmtpa (Exim 4.43) id 1CpLqj-0005KS-Ko; Fri, 14 Jan 2005 09:26:26 +0200 Message-ID: <41E774CA.8040808@hristov.com> Date: Fri, 14 Jan 2005 08:29:14 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a5) Gecko/20041102 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Christian Schneider CC: Torsten Roehr , 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> In-Reply-To: <41E5790D.2090402@cschneid.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iko.gotobg.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - hristov.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Re: Get name of extending class with static method call (PHP5) From: php@hristov.com (Andrey Hristov) 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