Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78394 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64462 invoked from network); 27 Oct 2014 17:02:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 17:02:58 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:38783] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 91/81-56216-1CA7E445 for ; Mon, 27 Oct 2014 12:02:57 -0500 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id 4B3F946B5F; Mon, 27 Oct 2014 18:03:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on km31408.keymachine.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.2 X-Spam-HAM-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.34] (ppp-93-104-15-160.dynamic.mnet-online.de [93.104.15.160]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id 8769446B5E; Mon, 27 Oct 2014 18:03:06 +0100 (CET) Message-ID: <1414429363.3228.41.camel@kuechenschabe> To: Michael Wallner Cc: Will Fitch , Stas Malyshev , PHP Internals Date: Mon, 27 Oct 2014 18:02:43 +0100 In-Reply-To: <544E03B6.5030707@php.net> References: <544DA1CD.9070109@php.net> <544DB15E.7090704@php.net> <4F8CEEE9-33CF-4138-9280-5488992C4AAB@php.net> <544E03B6.5030707@php.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) 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