Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79778 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93213 invoked from network); 17 Dec 2014 13:21:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Dec 2014 13:21:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.18 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.18 mout.gmx.net Received: from [212.227.15.18] ([212.227.15.18:53594] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/B0-23459-66381945 for ; Wed, 17 Dec 2014 08:21:43 -0500 Received: from [192.168.0.101] ([91.67.244.80]) by mail.gmx.com (mrgmx001) with ESMTPSA (Nemesis) id 0MNZgw-1Xzbit360Q-007BJY; Wed, 17 Dec 2014 14:21:37 +0100 Message-ID: <54918364.1060308@gmx.de> Date: Wed, 17 Dec 2014 14:21:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Rowan Collins , PHP internals References: <548FEE87.7020602@gmail.com> <549009EE.7040808@fischer.name> <54907683.2070509@gmail.com> <8AB6896C-D5DB-4471-BBD5-60784B2FC1BE@gmail.com> <54907EDE.6020500@gmail.com> <4E4F7392-154C-4282-8D5D-553194D09DCE@gmail.com> <5490DC22.2080605@gmx.de> <5490DD19.2080502@gmail.com> <5490E226.3070202@gmx.de> <5490E6F2.4050109@gmail.com> <549166B7.2030003@gmail.com> In-Reply-To: <549166B7.2030003@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:1iLUdWg4SXIR+x6mywfbVtaAHexOl6Xdk56/S02I0H0rh9YoABz N87rITsTIEcyCq7dL4CNUhHaP4L/x+ssK2uuuqrzQVCjiAy4iZJ9a/jouMP/Soxuy7ZMhoX YymVmjpeZiluoKUVazGTpUXrz2duhGT+JQp9sMPymTYZWHfAc32KYxyDSpngxyKXqResfpc DjBshY6P+ebcEf+CxlYQQ== X-UI-Out-Filterresults: notjunk:1; Subject: Re: [PHP-DEV] [RFC][VOTE] Objects as Keys From: cmbecker69@gmx.de (Christoph Becker) Rowan Collins wrote: > Stanislav Malyshev wrote on 17/12/2014 02:14: >> No, it's not possible. It is possible to call object method in an >> expression, and then use the result of the expression as an array key. >> But to do that you'd have to check that you're dealing with the object >> and the call the special method. > > I think what Christoph was getting at is that you could implement an > object map pretty simply by requiring the objects being added to > implement a particular interface, as in: > > .... > function add ( Hashable $obj ) { > $this->data[ $obj->getHash() ] = $obj; > } > .... > > The main thing that the current RFC would simplify is being able to > accept a mixture of objects and scalars without performing an extra > check; currently, you'd have to write something like this: > > .... > function add ( $scalar_or_obj ) { > if ( is_scalar($scalar_or_obj) ) { > $this->data[ $scalar_or_obj ] = $scalar_or_obj; > } elseif ( $scalar_or_obj instanceOf Hashable ) { > $this->data[ $obj->getHash() ] = $obj; > } else { > throw new InvalidArgumentException; > } > } > .... > > Which is certainly uglier, any maybe was the case that Guilherme had in > mind, but it's not like you have to build a whole new type of data > structure, just add a few lines of implementation. Yes, that is what I was trying to convey. :) > Compare that to trying to store the actual objects as keys, which would > require a lot more than a few lines of code to emulate in pure PHP. > Luckily, we have SplObjectStorage, which maybe makes that rather less > urgent as well. I agree. However, the RFC mentions a related open issue[1]: | Should SplObjectStorage support calling __hash for an object if it | exists? It might be good to discuss and resolve this issue, as Derick has already pointed out[2]. [1] [2] -- Christoph M. Becker