Re: [RFC] Using objects as keys
| From: | Will Fitch | Date: | Mon, 27 Oct 2014 02:23:20 +0000 |
| Subject: | Re: [RFC] Using objects as keys | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78362@lists.php.net to get a copy of this message | ||
> On Oct 26, 2014, at 8:37 PM, Stas Malyshev <smalyshev@gmail.com> wrote:
>
> Hi!
>
> I would like to present to your attention an RFC about using object as keys:
>
> https://wiki.php.net/rfc/objkey
>
Hi Stas!
I’m trying to wrap my head around a real-world use-case with this. We have spl_object_hash, which
effectively provides a unique hash for an object. If the intent is to provide an opportunity of
individual classes to decide what their hash is, couldn’t they provide that via __toString? I know
many frameworks use __toString to build out some implementation of an object (Zend form for
example), but the point of __toString is to provide a string representation of an object.
I want to say, I’m not at all against this - rather I support it. I’m just looking for the RFC
to provide an example that I and others can relate to.
> It was discussed in the past on the list:
> http://marc.info/?t=141145969600001&r=1&w=2
> and I think it makes sense to propose a formal RFC for it. Both the text
> and the code in the patch includes bits done by myself and Joe Watkins.
> The patch does not cover 100% of cases but should work for most
> reasonable scenarios, if something is wrong or you have ideas how to
> make it better please tell.
>
> The name __hash is not final, I am open to using __toKey instead or any
> reasonable alternative, we may also include a couple of options in the
> vote if that will be a point of disagreement.
>
> Thanks,
> Stas
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>