Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78411 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7654 invoked from network); 28 Oct 2014 00:28:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2014 00:28:40 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.173 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:58677] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EB/10-05596-733EE445 for ; Mon, 27 Oct 2014 19:28:40 -0500 Received: by mail-wi0-f173.google.com with SMTP id ex7so7883504wid.6 for ; Mon, 27 Oct 2014 17:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=user-agent:in-reply-to:references:mime-version :content-transfer-encoding:content-type:subject:from:date:to :message-id; bh=q8TqbjQEcs32Y+UjjFOutQdrzgWHqi6sYFtZAgvxjPs=; b=TPJB/2RCmYOyWG98vRKfCEbHTO0mNf+nO3MDTRpaM4elPQEXmEQC0DBlq/Dp66Qr9R iCv4g4qrc/7ZaJcRkp1G6znv/3PnIveTR+kpXjJz75IgR1FQaF70r1BWU0ngAoLetOge JTpIxxfN1M+hbYP6qGSvyzUnYTXM0rToCBh2O3SRZc7i7A+qT1TmDCmeatKPbIYCvmvW TuhP366ilyMPZnVSaAVZjqxUSKr8u8luEHGmj/zZASizsdcWSuMEVaQeoux4l/+n8Gdv CR5CsQHZA5XlooVGml6igT0uRsPozTYFvdS6KxiLOMRX21i+zefZUo5NPbr9lR5hhST2 7K2g== X-Received: by 10.194.173.10 with SMTP id bg10mr2610wjc.16.1414456116780; Mon, 27 Oct 2014 17:28:36 -0700 (PDT) Received: from [192.168.0.3] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id s8sm6192762wjx.9.2014.10.27.17.28.35 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 27 Oct 2014 17:28:35 -0700 (PDT) User-Agent: K-9 Mail for Android In-Reply-To: <544E8AE4.3040907@gmail.com> References: <544DA1CD.9070109@php.net> <544E8AE4.3040907@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Date: Tue, 28 Oct 2014 00:26:25 +0000 To: PHP Internals Message-ID: Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: rowan.collins@gmail.com (Rowan Collins) On 27 October 2014 18:11:48 GMT, Stas Malyshev wrote: >Hi! >> As others noted, it also prevents a full-fledged objects-as-key >> implementation in the future. >You do realize to have such implementation we'd need to rewrite our >hash >layer completely and also introduce the concept of immutable object, >otherwise changing the object would make the hash completely broken? >Which means it would probably never happen unless PHP engine is >radically rewritten. Regarding the immutability, I was wondering if it would be possible to treat the hash not as a magic method but a magic property, and then enforce immutability by saying that it could only be written once in a given instance. Generally speaking, a value or model object would be able to write to it in the constructor, and any incidental changes to the object (e.g. to lazy load data fields) would not affect it. Potentially, the hash implementation would "only" have to store an object reference next to the existing string (or int) key - all the logic of assigning hash buckets, performing equality checks within buckets, etc, would ignore the object and deal with the scalar value in exactly the same way as if it had been implicitly converted as with the current RFC. If two non-identical objects with the same hash identity were assigned to the same array, there would have to be a decision of which ended up referenced, but as long as it was defined and documented, I can't see either option being a massive problem. I realise that when it came down to brass tacks, it would be more complex than I'm implying - the memory impact of adding a pointer field on every key might be a problem, for instance - but it would be good not to dismiss it as impossible too quickly, and use up the syntax for a less powerful feature. >> In the end it causes issues and brings very little compared to an >> explicit call to convert an object to a key. >Same as __toString obviously is useless as you could just call a method >explicitly. You're putting words into someone else's mouth there. There's a big difference between "brings very little" and "is useless". There are certainly cases where an implicit call would be useful, but they are probably rather rarer than those where the user would want the object back afterwards.