Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78369 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96939 invoked from network); 27 Oct 2014 05:37:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 05:37:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=pthreads@pthreads.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=pthreads@pthreads.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pthreads.org from 209.85.212.169 cause and error) X-PHP-List-Original-Sender: pthreads@pthreads.org X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:34781] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/06-56216-A1ADD445 for ; Mon, 27 Oct 2014 00:37:31 -0500 Received: by mail-wi0-f169.google.com with SMTP id q5so5074147wiv.4 for ; Sun, 26 Oct 2014 22:37:27 -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=PeiL1mZuBnbSZ0EGraUr8I5gC8iYv4kxXyCtcYTCbUE=; b=lh6MBINffu7id2zDiElxgrDdkrOWwA9QUvBsXEAHgrAC1akzckowHRqRtvno3YL3gJ OpGAl52opX2ypVLXYkFqQnwwN4j2aY8BL9j7JbHa6En3FJJT1NAmXCQC9UntTxBXWCbJ UprUk2nzvfhOJ5a97Fbfbxgpo5WobV4r6UywsOaLxzyBo/NfLYsdfppSQ7UX5PR1sz5N WQbKOzNIDdkDn3Q/qR4wwIs7GxKIHFzGWOo9pwI6lQVl1MJxqOGSjQbBrv1bGBeAyeMb AltVsZxcSblfXVsR40ALcCDviaoISusjj4TbijSJ5CH9Kp2WhFfJwCO9DK/QNmzwO5IE FxBw== X-Gm-Message-State: ALoCoQkFwTUuk3PxouQaOi2ilMDavC3FLAMIA37nhE8UEqbKoNdNBrWN7wX99luadqJShPoFK3Zv X-Received: by 10.194.24.197 with SMTP id w5mr20481048wjf.71.1414388247713; Sun, 26 Oct 2014 22:37:27 -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 wr9sm1150700wjb.42.2014.10.26.22.37.26 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 26 Oct 2014 22:37:26 -0700 (PDT) Message-ID: <1414388245.2624.135.camel@localhost.localdomain> To: Stas Malyshev Cc: PHP Internals Date: Mon, 27 Oct 2014 05:37:25 +0000 In-Reply-To: <544DA1CD.9070109@php.net> References: <544DA1CD.9070109@php.net> 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 Sun, 2014-10-26 at 18:37 -0700, Stas Malyshev wrote: > Hi! > > I would like to present to your attention an RFC about using object as keys: > > https://wiki.php.net/rfc/objkey > > It was discussed in the past on the list: > http://marc.info/?t=141145969600001&r=1&w=2 > and I think it makes sense to propose a formal RFC for it. Both the text > and the code in the patch includes bits done by myself and Joe Watkins. > The patch does not cover 100% of cases but should work for most > reasonable scenarios, if something is wrong or you have ideas how to > make it better please tell. > > The name __hash is not final, I am open to using __toKey instead or any > reasonable alternative, we may also include a couple of options in the > vote if that will be a point of disagreement. > > Thanks, > Stas > Morning Stas, Nicely done. Whether SPL classes, or any other classes, should use the functionality should be left to another discussion. I wonder if it might be feasible to try and define what the contract of this method is, in the same kind of way as the Java docs do for Object.hashCode ? We can't have the exact same contract perhaps, but it might be useful to try to define it at this stage. 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, if we come up against the requirement to treat an object as a scalar for anything else, we have the machinery already and we don't have to add another magic method at that time. Not sure what others think about that ... I liked the name __hash better than __toKey, I like __toScalar better than those because it describes what the method is meant to do the best. Cheers Joe