On Mon, 2014-10-27 at 09:35 +0100, Michael Wallner wrote: > Actually, I see spl_object_hash($this) the 90% implementation of > __hash(), so how about making it the default for any object?
I agree - it might be a good default. To Will's question: It is not sufficient for all cases. Having a custom implementation allows the reverse. $u = new ustring("....."); $a[$u] = 42; unset($u); foreach ($a as $k => $v) { $u = u($k); // u() is a bad name, see other thread for that debate } also spl_object_hash is a unique identify, but given value objects having them in array_keys might mean that one doesn't want identity but grouped by value ... function get_date_for_item($item) { return new DateTime(...); } foreach ($items as $item) { $counts[get_date_for_item($item)]++; } here we create a new Datetime instance for each item, while multiple items might share the same data. in the loop we're counting distinct dates not DateTime instances. johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php