Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78377 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13963 invoked from network); 27 Oct 2014 07:55:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 07:55:27 -0000 Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 209.85.212.173 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 209.85.212.173 mail-wi0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:49331] helo=mail-wi0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/29-56216-D6AFD445 for ; Mon, 27 Oct 2014 02:55:26 -0500 Received: by mail-wi0-f173.google.com with SMTP id ex7so5540315wid.0 for ; Mon, 27 Oct 2014 00:55:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-type:mime-version:content-transfer-encoding; bh=4MVxVRrZjvO1WP/8/p1QJUi1En+OFVFo5cy1cyB0BZc=; b=K5FwdH884uA/FdnH2nKxuN8T+ezyLRKiFvhuIusuJWCYBiJbjcFbK5GTrWMwLVa3Tq zM3R7opDnn7oI8aJq2crN19yP84AktJz/WijZrOdVDZXDCgvJsJNoJLLXDkoAjwtFMtl 02Vn6ea9S0cUqfiQMVJOJuLGdElwYf9gjFr/yg7q3+h6ZKUE5Q0tqmQ9Zib0xk/sxVF9 +dGiHOKnpnQyBCrmPeUB6x09SJ2sSp6CSe6rMDVJzRMBheq7H6KmTQpykZ8bYoQCloBR z2aJuexrWXH+BFQFZlTbF5ZrdDnzYcvqxBYtM2IBkrLSJ5Tmg9jDnBH2eb9xpAimx41V E7OA== X-Gm-Message-State: ALoCoQldr9VnyilzF8gmQRH6mI8ZDnIw04Zf217kxd3KTLSbI9r/jU2q2+L08f2DeD27SWW69iYJ X-Received: by 10.194.161.166 with SMTP id xt6mr21315478wjb.1.1414396522857; Mon, 27 Oct 2014 00:55:22 -0700 (PDT) Received: from [192.168.1.67] (host86-130-70-156.range86-130.btcentralplus.com. [86.130.70.156]) by mx.google.com with ESMTPSA id gg18sm10934387wic.21.2014.10.27.00.55.21 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 27 Oct 2014 00:55:22 -0700 (PDT) Message-ID: <1414396519.2624.149.camel@localhost.localdomain> To: Stas Malyshev Cc: Patrick Schaaf , internals Date: Mon, 27 Oct 2014 07:55:19 +0000 In-Reply-To: <544DF70D.2040803@sugarcrm.com> References: <544DA1CD.9070109@php.net> <544DEFBE.8090107@sugarcrm.com> <544DF70D.2040803@sugarcrm.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Using objects as keys From: pthreads@pthreads.org (Joe Watkins) On Mon, 2014-10-27 at 00:41 -0700, Stas Malyshev wrote: > Hi! > > > Once your proposal is in the language, you will never, in the future, be > > able to add real support for objects as keys, because the semantics is > > blocked. > > This implies this support is not "real" and we want some other support. > I don't think I agree with either. > > > I do understand where your proposal is coming from and what it is trying > > to accomplish. But I think, at least, that it should clearly spell out > > that any ambition to really support objects as array keys in the base > > language, will then be given up. > > Was there ever such an ambition? Does somebody have any idea how to > properly do it and a reason why? > > > I hardly see how that would make sense. SplObjectStorate operates with > > object identity as determined by spl_object_hash, right? Changing that > > Now, it does, since there's no other option. However, in the future > there may be other options - i.e. objects whose identity is not the same > as their memory address. For example, for an object representing number > (GMP) or string (UString) their identity is their content, not their > memory address. Thus, if you want to use UString as an index, or have an > unique set of strings, spl_object_hash would not be your friend. > Of course, there's always an option of just telling it - e.g. by > providing an option to the ctor. > > > Right. Somehow python manages to live quite fine with that fact. > > For some definitions of "quite fine", I presume - I can't see how a > hashtable that repeatedly calls user code can be efficient. It probably > isn't. > > > Right. You don't do that when your object implements __hash__ and __eq__. > > Or, more precisely, you're asked nicely not to do it - because there's > no way to actually ensure it. > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > Morning, As already pointed out by Stas, using objects as array keys would require a rewrite of the HashTable API, something integral to PHP. I'm not sure that is realistic, or possible. I think probably, the best way we can support objects as collection keys is with the introduction of generics, something totally disconnected from this RFC, that nobody has a working patch for. Cheers Joe