Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78480 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94906 invoked from network); 30 Oct 2014 18:32:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Oct 2014 18:32:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 108.166.43.107 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 108.166.43.107 smtp107.ord1c.emailsrvr.com Linux 2.6 Received: from [108.166.43.107] ([108.166.43.107:52350] helo=smtp107.ord1c.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 07/FB-33916-84482545 for ; Thu, 30 Oct 2014 13:32:41 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp6.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id 5A156802C8; Thu, 30 Oct 2014 14:32:38 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp6.relay.ord1c.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 02F3680275; Thu, 30 Oct 2014 14:32:37 -0400 (EDT) X-Sender-Id: smalyshev@sugarcrm.com Received: from Stass-MacBook-Pro.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net [108.66.6.48]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA) by 0.0.0.0:465 (trex/5.3.2); Thu, 30 Oct 2014 18:32:38 GMT Message-ID: <54528445.8080604@sugarcrm.com> Date: Thu, 30 Oct 2014 11:32:37 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Larry Garfield , "internals@lists.php.net" References: <544DA1CD.9070109@php.net> <4ED7146272E04A47B986ED49E771E347BD7E35E061@Ikarus.ameusgmbh.intern> <51CF9ADE-2E04-4BC0-9E5C-B93498251F59@php.net> <54527E7E.2020505@garfieldtech.com> In-Reply-To: <54527E7E.2020505@garfieldtech.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > Put another way, I think a key question here is: > > class Foo { > public $bar; > } > > $a = new Foo; > $a->bar = 'baz'; > $b = new Foo; > $b->bar = 'baz'; > > $arr[$a] = true; > $arr[$b] = true; > > > Does $arr now contain one value or two? That depends on the semantics of class Foo. If Foo is something like UString, then it should contain one value, since UString is a value object (https://en.wikipedia.org/wiki/Value_object) - or at least it should be. However, if Foo represents something having separate identity - i.e. it's a Person class and 'bar' represents name - then of course it should contain two values, since the name is not the sole source of Person's identity. So the decision is on you as a programmer. And to give you the tool to make this decision and let PHP engine know about is exactly the point of this RFC. > If the desire is for it to contain 2, then spl_object_hash($a) already > has that covered, I think. > > If the desire is for it to contain 1, then the proposal sounds like a > way to normalize Foo::stringifiedValueObjectEquivalent(). You can describe it as such, but in a proper standartized way and with syntax that allows you to use same syntax constructs on all keys and not have to check each time if it's a special value and call a special function on it (same purpose as for __toString). -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/