Re: [RFC] Using objects as keys
| From: | Andrea Faulds | Date: | Mon, 27 Oct 2014 09:15:00 +0000 |
| Subject: | Re: [RFC] Using objects as keys | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78383@lists.php.net to get a copy of this message | ||
> On 27 Oct 2014, at 06:36, Stas Malyshev <smalyshev@gmail.com> wrote:
>
> Hi!
>
>> It seems __toScalar might be a good name, this is what the method
>> actually does, the engine then coerces to a type suitable for use as a
>> key, but you can return a double. It might be more forward thinking
>> therefore to use the name __toScalar, while today we'd only be using
>> it for this,
> __toScalar does not express the fact why we are calling it - to use it
> as a key. It's not just a scalar conversion, it's conversion for the
> purpose of hashing.
It would also be used by Anthony’s Object Cast To Types
(https://wiki.php.net/rfc/object_cast_to_types) RFC if revived, and __toScalar makes more sense
there.
Personally, I think __toKey is best. It’s not a hash as such, it’s an equivalent string or
integer key value. It fits nicely with __toString, and would fit with other __to* functions like
__toInt if that RFC was revived. People would look at __hash and think it’s sql_object_hash, which
it isn’t.
--
Andrea Faulds
http://ajf.me/