Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10745 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48295 invoked by uid 1010); 24 Jun 2004 07:59:15 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 48219 invoked from network); 24 Jun 2004 07:59:14 -0000 Received: from unknown (HELO newweb.akbkhome.com) (202.81.246.113) by pb1.pair.com with SMTP; 24 Jun 2004 07:59:14 -0000 Received: from develop ([192.168.0.40] helo=alan ident=mail) by newweb.akbkhome.com with esmtp (Exim 4.33) id 1BdPKi-0001TZ-O4; Thu, 24 Jun 2004 16:11:44 +0800 Received: from alan ([127.0.0.1] helo=akbkhome.com ident=alan) by alan with esmtp (Exim 3.36 #1 (Debian)) id 1BdPDf-0002zF-00; Thu, 24 Jun 2004 16:04:27 +0800 Message-ID: <40DA8B0A.6070609@akbkhome.com> Date: Thu, 24 Jun 2004 16:04:26 +0800 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7b) Gecko/20040422 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Taco van den Broek CC: internals@lists.php.net References: <40DA29C3.1090301@velum.net> <20040624074757.1883.qmail@pb1.pair.com> In-Reply-To: <20040624074757.1883.qmail@pb1.pair.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: static/object method From: alan@akbkhome.com (Alan Knowles) the E_STRICT warnings on static calls to non static methods are probably usefull, (as $this could be defined totally randomly), so it does make some sense.. btw: does that mean: class a { function find() { } } class b extends a { function find() { } } // call the toplevel parent method.. (skip the imediate parent) class c extends b { function find() { a::find() } } $a = new c; $c->find(); illicits and E_STRICT warning??? (sorry I havent got the latest PHP5 compiled ATM..) Regards Alan Taco van den Broek wrote: > Hans Lellelid wrote: > >> Hi all, >> >> I have a pattern I'm trying to implement in PHP5 using a class that >> could be called statically or non-statically. Perhaps "pattern" gives >> this too much legitimacy :) I can't figure out how to do this & >> wanted to ask if a) it's possible at all and b) if there's been any >> solution discussed for such an approach. >> >> Here's what I'm trying to do, but can't figure out a way in PHP5 (or a >> non-hack way in PHP4): >> >> - AuthorFinder is a class that can be used statically for default >> behavior or instantiated if customized behavior is needed. >> >> static, default behavior, probably accounts for 80% of uses: >> >> $c = new Criteria(Author::NAME, "Leo"); >> $a = AuthorFinder::find($c); > > > You pass your criteria to your search class as instantiated objects, why > don't you pass your parameters/config flags as another type of object? > Maybe like this: > > $c = new Criteria(Author::NAME, "Leo"); > $f = new ConfigFlag(AuthorFinder::LIMIT, '5'); > $a = AuthorFinder::find($c, $f); > > You could then check the $f object for any customizations, just like you > check the $c object for where to search. > >> >> instantiated behavior for performing customizations: >> >> $c = new Criteria(Author::NAME, "Leo"); >> $af = new AuthorFinder(); >> $af->setLimit(5); >> $a = $af->find($c); >> >> Is there *any* way to accomplish that in PHP5? I can't reference >> $this -- even to check isset() (which would probably be misleading >> anyway) from inside a method declared as static. If I do not declare >> the method static then calling it statically triggers E_STRICT error >> which I want to avoid since I'm writing PHP5 code. Perhaps I'm >> missing an obvious solution, in which case I apologize & probably >> should have asked php-general. >> >> It would be *really* cool if PHP could support this type of pattern, >> as there have been a few cases where I've wanted to apply this in >> PHP5. Perhaps this has already been discussed & I just didn't notice. >> >> Thanks, >> Hans > > -- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com