> On Oct 27, 2014, at 1:36 AM, Stas Malyshev <smalys...@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.
I think that’s the general confusion around this. Generally, the examples provided (Java/Ruby/Python) are based on two things: 1. The value returned is a signed 32-bit (debatable) integer 2. Each hash is calculated based on the properties available (and assigned). With this in mind, should we not expect, at the very least, and integer on each return? For example: class Company { private $companyId; private $clientId; public function __construct($companyId, $clientId) { $this->companyId = (int) $companyId; $this->clientId = (int) $clientId; } public function __toHash() { return $this->companyId * $this->clientId; } } This is a trivial example, it can be used to define a simple approach for object “uniqueness” and prevent potentially prevent duplicate hashes in a structure. That said, with PHP’s typeless approach, I understand the case could be made for combining values into a string. To me, it seems more logical and uniform to require an integer - whether signed or unsigned. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php