Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10741 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64811 invoked by uid 1010); 24 Jun 2004 01:58:46 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 64771 invoked by uid 1007); 24 Jun 2004 01:58:46 -0000 Message-ID: <20040624015846.64770.qmail@pb1.pair.com> To: internals@lists.php.net Date: Wed, 23 Jun 2004 22:58:35 -0300 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 References: <40DA29C3.1090301@velum.net> In-Reply-To: <40DA29C3.1090301@velum.net> X-Enigmail-Version: 0.83.6.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 201.8.2.4 Subject: Re: static/object method From: accerqueira@superig.com.br (Andre Cerqueira) Hi I think it should be constructor's job to set up an instance with the defaults. (no need for static in this case) Am i missing something? 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); > > 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