Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79779 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95238 invoked from network); 17 Dec 2014 13:34:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Dec 2014 13:34:56 -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 74.125.82.50 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.50 mail-wg0-f50.google.com Received: from [74.125.82.50] ([74.125.82.50:41014] helo=mail-wg0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/11-23459-E7681945 for ; Wed, 17 Dec 2014 08:34:55 -0500 Received: by mail-wg0-f50.google.com with SMTP id a1so20427235wgh.9 for ; Wed, 17 Dec 2014 05:34:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=kRBlei1wboNBXTkoB91u1Pw8AuB/DXxY+6VUbpHvKk0=; b=gmDJVYvMeVco2eHN6xVwWgsQjlpr3VHLuE3/oOerdx44Uq1NnG2qJjpShZzgg5GS29 /BpS8bCU7RYCve3zuDlIw/1APKaUm32V2ViJVBW8543ar8KFi36gNGeCmmQM28R/lcVw 5pA6aIwjf92Fe/r9t5+P/vXVKw6CyrtVTZA8/dbzGAiIjM/0h4ndTVqPGmk6J5Nv/3cP LzvPk/9EQNYXIvSoB7JQpKrBk+ee38aueImXSFoLI6OMnwt9ULEoU1qZrz4lhcYOCXjD cdbNWoF3A8k6x5JWLj29UvDn7DV6mh0KB9z3ZzYwpIxHqQptCEr6AUoqK/DRJl09T7Vt bXcg== X-Received: by 10.180.211.2 with SMTP id my2mr14368196wic.3.1418823290983; Wed, 17 Dec 2014 05:34:50 -0800 (PST) Received: from [192.168.0.148] ([62.189.198.114]) by mx.google.com with ESMTPSA id wb9sm6165159wic.20.2014.12.17.05.34.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 05:34:49 -0800 (PST) Message-ID: <5491866F.8000404@gmail.com> Date: Wed, 17 Dec 2014 13:34:39 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: <548FEE87.7020602@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][VOTE] Objects as Keys From: rowan.collins@gmail.com (Rowan Collins) guilhermeblanco@gmail.com wrote on 17/12/2014 12:43: > Answering the question of Christopher Becker. It is not possible to > traverse and get your desired elements. > How would you achieve a foreach by key (returning object) without having to > store a separate list and track by hash or through an interface? SplObjectStorage supports that mechanism, although it's not the most intuitive design. See this comment in the manual: http://php.net/manual/en/class.splobjectstorage.php#114059 As others have pointed out, this proposal does *not* support that usage, because the hash function is one-way, and you cannot get back the object based only on the calculated key. All it does is reduce the boilerplate needed for hashing an object to produce a suitable array key.