2014-10-27 16:54 GMT+01:00 Levi Morrison <le...@php.net>:

> > I would like to present to your attention an RFC about using object as
> keys:
> >
> > https://wiki.php.net/rfc/objkey
>
> A few points I have against this proposal, as I understand it:
>
>   - It does not store the object, only the result of  `__hash`.
> Without the actual object this is not helpful for any use-case I have.
>
>   - Using a method in the object prevents you from hashing on
> different members of the objects for different uses. For example,
> there is a User object. Most of the time the User::id will be used for
> the hash. However, sometimes the hash needs to be on User::username.
> If the hashing code is pushed inside the object and call it
> automatically then you can't hash on the different values.
>
> In summary 1) the hashing function should be external to the object,
> 2) should not be invoked magically, and 3) the object needs to be
> stored. This can already be done in user-land; here is one such
> example that I have created but there are others:
> https://github.com/morrisonlevi/Ardent/blob/master/src/HashMap.php
>
>
Although I don't care very much for the first two points, the third point
is very alarming. Yes, we should have the option to get the objects used as
keys, otherwise the new functionality does not offer much.


Lazare INEPOLOGLOU
Ingénieur Logiciel

Reply via email to