Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78371 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1953 invoked from network); 27 Oct 2014 06:49:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 06:49:22 -0000 Authentication-Results: pb1.pair.com header.from=willfitch@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=willfitch@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 66.111.4.25 as permitted sender) X-PHP-List-Original-Sender: willfitch@php.net X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:54392] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/C6-56216-1FAED445 for ; Mon, 27 Oct 2014 01:49:21 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id AAE952095A for ; Mon, 27 Oct 2014 02:49:18 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Mon, 27 Oct 2014 02:49:18 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:content-type:mime-version :subject:from:in-reply-to:date:cc:content-transfer-encoding :message-id:references:to; s=smtpout; bh=JnKX2XdKaXiAa1AnTW14DpG VQoY=; b=u4qiF4pSHMR03IZtW03tiP7+ArGg2C1zwHjg6UsNuvcxC+k19VaMUjT ac8G239ARtt6WMmDgss5floNrWpMzsbuFAzWDRohnO1YqzcBpYJJEeXysoPQXGnT bWgyHlmH9DB8nF4IYOmbpQ1n9DenmbJ5AGeB7cYXrlWEVgKGPTAw= X-Sasl-enc: A8xcpWQEQqt+obRHnXgWfKpuCPLo0XHxID9FT4CQ6hWX 1414392558 Received: from [192.168.1.137] (unknown [24.183.225.156]) by mail.messagingengine.com (Postfix) with ESMTPA id 3DF92C0000A; Mon, 27 Oct 2014 02:49:18 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: <544DE7FF.6030809@gmail.com> Date: Mon, 27 Oct 2014 01:49:17 -0500 Cc: Joe Watkins , PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <544DA1CD.9070109@php.net> <1414388245.2624.135.camel@localhost.localdomain> <544DE7FF.6030809@gmail.com> To: Stas Malyshev X-Mailer: Apple Mail (2.1990.1) Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: willfitch@php.net (Will Fitch) > On Oct 27, 2014, at 1:36 AM, Stas Malyshev = wrote: >=20 > Hi! >=20 >> 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,=20 > __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=E2=80=99s 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).=20 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 =3D (int) $companyId; $this->clientId =3D (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 =E2=80=9Cuniqueness=E2=80=9D and prevent potentially prevent = duplicate hashes in a structure. That said, with PHP=E2=80=99s 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. >=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20