Re: [RFC][VOTE] Objects as Keys
| From: | Christoph Becker | Date: | Wed, 17 Dec 2014 01:53:42 +0000 |
| Subject: | Re: [RFC][VOTE] Objects as Keys | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79764@lists.php.net to get a copy of this message | ||
Stanislav Malyshev wrote:
>> AIUI, this RFC is meant to introduce some sugar only. Wouldn't it be
>
> I'm not sure what you mean by "some sugar only". It introduces the
> capability of using objects in array key context, which was not
> available until now.
Yes, but it is already possible to call an object's method in array key
context, so in combination with an appropriate interface the same can be
accomplished.
>> possible to have object hashes without __hash(), by introducing a
>> respective interface (maybe "Hashable" or "Identifiable") and requiring
>> the appropriate classes to implement this interface?
>
> It's possible and essentially the same, replacing magic method (which is
> how things were done in PHP since forever until now) with interface -
> which probably would be slower to check, would still require dedicated
> method name, probably starting with __, and will essentially do the same.
I didn't mean to argue against the RFC, but merely wanted to point out
that one could have object hashes without the proposed magic method
(albeit in a more contrived way).
Frankly, I don't understand Guilherme's claim:
| With this enhancement it would now become possible to implement a
| proper IdentityMap.
It seems to me that is already possible since PHP 5.0.0. I may be
missing an important detail, though.
BTW: as a userland developer I would not have called the dedicated
method __X, because __* is reserved for PHP's internal usage, AIUI.
--
Christoph M. Becker