Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54397 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11988 invoked from network); 5 Aug 2011 06:00:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2011 06:00:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=lars.schultz@toolpark.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lars.schultz@toolpark.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain toolpark.com from 195.49.42.12 cause and error) X-PHP-List-Original-Sender: lars.schultz@toolpark.com X-Host-Fingerprint: 195.49.42.12 mail1.screenlight.ch Received: from [195.49.42.12] ([195.49.42.12:65293] helo=mail1.screenlight.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/62-08937-CF68B3E4 for ; Fri, 05 Aug 2011 02:00:30 -0400 Received: from [192.168.1.112] ([192.168.1.112]) (authenticated user lars.schultz@toolpark.com) by mail1.screenlight.ch (Kerio Connect 7.0.2 patch 1) (using TLSv1/SSLv3 with cipher AES256-SHA (256 bits)) for internals@lists.php.net; Fri, 5 Aug 2011 08:00:21 +0200 Message-ID: <4E3B86F5.4000304@toolpark.com> Date: Fri, 05 Aug 2011 08:00:21 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 To: internals@lists.php.net 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> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE] Weak References From: lars.schultz@toolpark.com (Lars Schultz) Am 04.08.2011 23:19, schrieb Chris Stockton: > 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. Though I have never used java, I believe Weak- and SoftReferences would tremendously simplify certain, very specific applications. * WeakReferences for implementing the observer pattern aka. keeping a list of handlers for certain events. * SoftReferences for caching aka. keeping a list of objects to be returned or created by a factory If used this way, there is no danger of null-fatal-errors, because the event-trigger is aware of the volatile nature of its handlers and the factory knows that it's cached objects might be discarded. In fact, I'd say that Weak-/Soft-References are a better fit in PHP than in Java, because the ->get() methods return type is non-specific (has to be cast in java?)...which matches PHPs untyped approach. > 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. Could you explain ticks?...to me a tick is a nasty little creature that bites and gives you infections;)