Re: [RFC][VOTE] Objects as Keys
| From: | Christoph Becker | Date: | Wed, 17 Dec 2014 13:07:46 +0000 |
| Subject: | Re: [RFC][VOTE] Objects as Keys | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79776@lists.php.net to get a copy of this message | ||
guilhermeblanco@gmail.com wrote:
> 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?
AIUI, the RFC proposes that __hash() returns a string or an int, and
this value (not the object itself) will be stored and retrieved as key
of the array.
<https://wiki.php.net/rfc/objkey#proposal>:
| Create a new magic method, __hash() which is called when object is
| supplied as a hash key, and returns string or integer that is used as
| the hash key.
--
Christoph M. Becker