Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78472 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76808 invoked from network); 30 Oct 2014 16:44:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Oct 2014 16:44:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.214 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.214 mail4-2.serversure.net Linux 2.6 Received: from [217.147.176.214] ([217.147.176.214:37415] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/38-33916-4EA62545 for ; Thu, 30 Oct 2014 11:44:21 -0500 Received: (qmail 21058 invoked by uid 89); 30 Oct 2014 16:44:18 -0000 Received: by simscan 1.3.1 ppid: 21046, pid: 21053, t: 0.2607s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.8?) (lester@rainbowdigitalmedia.org.uk@86.163.79.60) by mail4.serversure.net with ESMTPA; 30 Oct 2014 16:44:17 -0000 Message-ID: <54526AE0.7060702@lsces.co.uk> Date: Thu, 30 Oct 2014 16:44:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 MIME-Version: 1.0 To: internals@lists.php.net References: <544DA1CD.9070109@php.net> <4ED7146272E04A47B986ED49E771E347BD7E35E061@Ikarus.ameusgmbh.intern> <51CF9ADE-2E04-4BC0-9E5C-B93498251F59@php.net> <5452158A.6070003@lsces.co.uk> <2BB0BBCF-87D2-4E13-9B59-B18A17572B37@gmail.com> In-Reply-To: <2BB0BBCF-87D2-4E13-9B59-B18A17572B37@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: lester@lsces.co.uk (Lester Caine) On 30/10/14 15:06, Rowan Collins wrote: > On 30 October 2014 10:40:10 GMT, Lester Caine wrote: >> On 30/10/14 07:19, Will Fitch wrote: >>> The magic method is more of a PHP approach while an interface would >> be more appropriate. That said, this RFC is a true representation of a >> hash vs something like spl_object_hash. That’s what causes user >> confusion. spl_object_hash would’ve been better served as a name like >> spl_object_id or spl_object_hash_id. Something that indicates >> uniqueness regardless of the values of a particular object. >> >> The bit of the jigsaw I'm still missing here is just what the object of >> the exercise is? > > > There are many different use cases for hash keys, and PHP's "array" type is particularly flexible. > > For instance, de-duplicating a list of items ($foo[$x] = $x), or counting occurrences of each ($foo[$x]++) > > In the case of a simple DB model, the primary key value is the obvious choice for the hash key, but not all objects are as simple as that. > > Being able to store the object itself would save having to recreate it from the key, e.g. looking the ID back up for a DB model, or re-parsing UTF8 for a UString. But that statement makes no sense! Accessing the object is via a handle, so you will always have a pointer to it. Adding some abstract identifier to describe the pointer is always going to be secondary to the pointer itself? You need a name to create an object and creating an array of objects needs keys which can either just be the PHP default location in the array, or you add a name to that key in some way. The content of the location in the array is the handle to the object. It will never be 'the object'? To look up an object you need to know something about the object and that is either some subset of the object or an abstract reference which one looks up in order to access the pointer. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk