Re: [RFC][VOTE] Objects as Keys
| From: | Rowan Collins | Date: | Wed, 17 Dec 2014 13:34:39 +0000 |
| Subject: | Re: [RFC][VOTE] Objects as Keys | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79779@lists.php.net to get a copy of this message | ||
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.