RE: [PHP-DEV] [RFC] Using objects as keys
| From: | Christian Stoller | Date: | Thu, 30 Oct 2014 07:13:27 +0000 |
| Subject: | RE: [PHP-DEV] [RFC] Using objects as keys | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78452@lists.php.net to get a copy of this message | ||
From: Alexander Lisachenko [mailto:lisachenko.it@gmail.com], Sent: Monday, October 27, 2014 11:18 AM
> Hello, internals!
>
>> 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.
>
> I like this idea with custom hash implementation because spl_object_hash()
> is not reliable when objects are quickly created/destroyed, so hashes can
> be the same for several different objects. However, will it be better to
> introduce an interface for that? For example, Hashable can be a good name
> (like Traversable one). Default implementation then can be a simple trait
> that will be added later to the concrete class.
I like the idea introducing an interface for this functionality, instead
of adding a further magic method. But I think anything like "hash" or
"hashable" is confusing for users.
Maybe something like
interface ArrayKeyConvertable
{
function toArrayKey();
}
Christian