Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54391 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16320 invoked from network); 4 Aug 2011 21:19:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 21:19:06 -0000 Authentication-Results: pb1.pair.com header.from=chrisstocktonaz@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chrisstocktonaz@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.172 as permitted sender) X-PHP-List-Original-Sender: chrisstocktonaz@gmail.com X-Host-Fingerprint: 209.85.210.172 mail-iy0-f172.google.com Received: from [209.85.210.172] ([209.85.210.172:33483] helo=mail-iy0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 49/51-08937-9CC0B3E4 for ; Thu, 04 Aug 2011 17:19:05 -0400 Received: by iye7 with SMTP id 7so971551iye.31 for ; Thu, 04 Aug 2011 14:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=UQMoEE/1s8xDf3/lQmYhwx+t2/A0HSnDzllsLyNXe4U=; b=xZR6kZz1+v0mDqL+91wwPpU1OfdfGqcvBah9cuDUhj4V8e+MDz2mECcUpETKWmuSwU +jAITiH9FXrNcjuw6BjZO+L+pYm1OE+x7K89k8tLgvwJsLakQB4RufaIHL435R/fzJho URQM0amlg7jIEDObxdpwSiFAeP2OuOn3kC6UQ= MIME-Version: 1.0 Received: by 10.42.149.131 with SMTP id w3mr1054808icv.340.1312492741927; Thu, 04 Aug 2011 14:19:01 -0700 (PDT) Received: by 10.42.197.132 with HTTP; Thu, 4 Aug 2011 14:19:01 -0700 (PDT) In-Reply-To: References: <4E3898B0.40809@sugarcrm.com> <4E38EC0C.9080304@lerdorf.com> <4E38FA2E.4030605@lsces.co.uk> <4E38FC67.9090200@toolpark.com> <4E39E89F.8060605@sugarcrm.com> <4E3A3643.2070305@toolpark.com> <4E3A4793.2070209@sugarcrm.com> <4E3A91E8.1020107@toolpark.com> <4E3ACA42.8000001@sugarcrm.com> Date: Thu, 4 Aug 2011 14:19:01 -0700 Message-ID: To: Ferenc Kovacs Cc: Stas Malyshev , Lars Schultz , "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [VOTE] Weak References From: chrisstocktonaz@gmail.com (Chris Stockton) Hello, On Thu, Aug 4, 2011 at 1:53 PM, Ferenc Kovacs wrote: > so as I see you didn't really addressed the proposed use-case of the > Weak References, just stated what everybody is aware of: one can cache > and free objects "manually" without the need of Weak References. > and while that is true, I still think that this could be a great asset > for creating high quality components. I myself oppose WeakReference in java and I do not see my opinion changing for PHP ... unfortunately I think WeakReference's are even nastier in PHP because of it's error handling. You see it is very common when weak references are used in java too follow one of two paradigms, fall through with NPE's, or state/null checks. With PHP, you may not "test" the validity of a weak reference simply by accessing it, you will get a uncatchable fatal error. So in PHP your only option when consumers are obtaining weak reference handles, is to check their validity before use, whether that is a call into some registry, or a null check of the reference itself, whatever.. it still leads to checks to make sure that reference wasn't collected. This added complexity in the WeakReference consumer makes me unable see any purpose through the inconvenience and unpredictability they bring. > btw. it was suggested before, but I really think, that it would be a > good idea to have a register_ function which would allow you to pass a > callable, which will be called when the memory usage reaches a given > value. > that would make a good addition to resolve some of use cases mentioned > in this thread. I use ticks to do this in a CLI daemon I wrote, worked out pretty well. Not saying a specialized function isn't needed but I think ticks aren't to far from convenient to require such.