Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55159 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9511 invoked from network); 3 Sep 2011 16:29:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Sep 2011 16:29:57 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:47499] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/22-24201-306526E4 for ; Sat, 03 Sep 2011 12:29:56 -0400 Received: by bkas6 with SMTP id s6so3047158bka.29 for ; Sat, 03 Sep 2011 09:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=ks/ya2mPhQuO/HVKu1PaAAVsLA5tMDTimBR21JDf7CQ=; b=qAlrvJi+tveIofCxuUXu1MiFjMbTwuqjAK/cDYjElwquBwxXXFyR9mEZMBUNPA2los cPEKje8y4Exqb2RRcWGQJv9Kspa3D4JUCHn1tUSnWZF7BYn2k+imw/QCQ9GLVzjkYbWx kXDmFGn6HBfrFc/99qrZNhfoo3dgP2y8IqSHA= MIME-Version: 1.0 Received: by 10.204.135.12 with SMTP id l12mr1300622bkt.194.1315067390695; Sat, 03 Sep 2011 09:29:50 -0700 (PDT) Sender: ekneuss@gmail.com Received: by 10.204.40.199 with HTTP; Sat, 3 Sep 2011 09:29:50 -0700 (PDT) In-Reply-To: <4E62443C.9010603@toolpark.com> References: <4E39E89F.8060605@sugarcrm.com> <4E3A3643.2070305@toolpark.com> <4E3A4793.2070209@sugarcrm.com> <4E3A91E8.1020107@toolpark.com> <4E3ACA42.8000001@sugarcrm.com> <4E3BF930.9030701@toolpark.com> <4E3C5EDE.3030401@toolpark.com> <4E3D073A.9050709@toolpark.com> <4E412E3E.2@toolpark.com> <4E62443C.9010603@toolpark.com> Date: Sat, 3 Sep 2011 18:29:50 +0200 X-Google-Sender-Auth: 0YuBNK0QM34cQizERHNDendgB_g Message-ID: To: Lars Schultz Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001517478c00ad980004ac0bfcb8 Subject: Re: [PHP-DEV] [VOTE] Weak References From: colder@php.net (Etienne Kneuss) --001517478c00ad980004ac0bfcb8 Content-Type: text/plain; charset=UTF-8 Hi, On Sat, Sep 3, 2011 at 17:14, Lars Schultz wrote: > Am 03.09.2011 13:56, schrieb Etienne Kneuss: > >> Indeed, I planned to implement that as well, I haven't had the time to do >> it >> >> yet though. It should happen in the following weeks. >> > > Not to keep you from doing this...but couldn't that easily be solved by > using a simple associative php array like this: > > $pseudoWeakMap = array(); > $pseudoWeakMap[spl_object_**hash($obj)] = new WeakReference($obj); > > or did I misunderstand the concept? I hope I'll have a chance to use > WeakReferences soon in my project;) > > My understanding of weak maps would be a way to associate data with objects, and have the data be freed once the object itself is deleted. So basically in example: $map = new WeakMap; $obj = new Class; $map[$obj] = .. some data .. ... var_dump($map[$obj]); // .. some data .. unset($obj); // unsets $map[$obj] automatically as well. var_dump(isset($map[$obj])); // bool(false) So sure, it could be implemented using spl_object_hash and having the Class destructor take care of deleting all that associated Data, but using weakmaps would make it far more convenient. Best, > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch --001517478c00ad980004ac0bfcb8--