Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66796 invoked from network); 29 Nov 2014 18:22:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2014 18:22:21 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:47135] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FA/B0-62697-DDE0A745 for ; Sat, 29 Nov 2014 13:22:21 -0500 Received: by mail-wi0-f176.google.com with SMTP id ex7so21028363wid.9 for ; Sat, 29 Nov 2014 10:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=E2ScY6w75CvszsRGlmptwyDfLjUtnUMDAZVg00MYcd4=; b=RJUIepwOZb7Iq/ZjjyrZ1ZWfhpmOX7qsC+mnGMBWl7bw2WRJOJalUsDHkdpb7vyWSc BqwB9316WqIQBt/dEFlPaqZKdrmjjztrNL6jVeYwDZ6f0ZPllwdTgmb7ppVsdZJP/erG 6RcziquseDyvCvX9VclBi3qZMHvoF/AWQig7NqAH434QAfh4s62zVNOlBFUiytW4Tu3x fYJfKK8OsF5zrL1AklDewMNncOXXb+sKf7vFRvxC12pMwfNfRAinZZAI0JCexmqYFJKr 9CeogN7MDwj+TsLjqJtFzcpofhjPXiIujc1+OHhgkyhQ/KsJ8tOlpZjFyn0AQvj1ElyW 2pUQ== X-Received: by 10.194.24.103 with SMTP id t7mr59703896wjf.15.1417285337065; Sat, 29 Nov 2014 10:22:17 -0800 (PST) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id bj7sm19973474wjc.33.2014.11.29.10.22.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Nov 2014 10:22:16 -0800 (PST) Message-ID: <547A0ECC.5080604@gmail.com> Date: Sat, 29 Nov 2014 18:22:04 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: PHP Internals List References: <5479038D.8070700@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] New function: spl_object_id() or spl_object_handle() From: rowan.collins@gmail.com (Rowan Collins) On 29/11/2014 18:04, Bostjan Skufca wrote: > On 29 November 2014 at 00:21, Rowan Collins wrote: >> On 28/11/2014 01:13, Bostjan Skufca wrote: >>> A function called spl_object_hash() exists, >>> but it returns identical hashes for equal objects. >> In case it's been lost in the noise, no it doesn't. > Ouch. I am terribly sorry about this mistake, it really does not. > > However, having word "hash" in the function name suggests that > returned hash is generated by the object's contents, too. I just > noticed that the first comment explains that this is not the case, > which I confirmed with additional testing. > > To quote a part of first sentence of Wikipedia on "Hash function": > "...with slight differences in input data producing very big > differences in output data." > > So, to sum it up: spl_object_hash indeed does what I initially > required, but I was mislead by the "hash" word in its name, and the > environment where I was trying to use it (unable to bring two object > references in the same place easily). > > But I would maybe suggest changing the name to spl_object_id (and > keeping ..._hash alias for backward compatibility). I can see the confusion, but the output is more like a hash than an ID - it's just that the input of the hashing is the object's immutable metadata, not its current internal state. Specifically, it's an arbitrary value which has no meaning beyond being unique for each input, and easily comparable between outputs. That said, it does do rather poorly on the "small difference in input, large difference in output" stakes; it could do with being run through something like MD5 to make it more well distributed, and easier for debugging by human eyes. Of course, you can always just do that in userland with md5(spl_object_hash($foo)) Regards, -- Rowan Collins [IMSoP]