On Sun, 2014-10-26 at 18:37 -0700, Stas Malyshev wrote: > Hi! > > I would like to present to your attention an RFC about using object as keys: > > https://wiki.php.net/rfc/objkey > > 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 >
Morning Stas, Nicely done. Whether SPL classes, or any other classes, should use the functionality should be left to another discussion. I wonder if it might be feasible to try and define what the contract of this method is, in the same kind of way as the Java docs do for Object.hashCode ? We can't have the exact same contract perhaps, but it might be useful to try to define it at this stage. 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, if we come up against the requirement to treat an object as a scalar for anything else, we have the machinery already and we don't have to add another magic method at that time. Not sure what others think about that ... I liked the name __hash better than __toKey, I like __toScalar better than those because it describes what the method is meant to do the best. Cheers Joe -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php