Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79772 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77012 invoked from network); 17 Dec 2014 11:19:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Dec 2014 11:19:36 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:44873] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/10-10120-7C661945 for ; Wed, 17 Dec 2014 06:19:36 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so15685775wiv.1 for ; Wed, 17 Dec 2014 03:19:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=X2GMpNZrsQkZ6iRCwDClik4R74ugg6qFNYnOus0arkQ=; b=wDbsOb+VtfXNZKtf7FLyHGbAED4QJIeoRnwTN7Kkx2olQ3SrDt1NivMX44tMO59xUS Ix/ziM+FWcJQ4vv4uojc9OMlKeAMAAsItsan3wBeVDktnVRYjE2GGtev9As8jm8eZ8p9 vwcPF50TNoXzCaycrUGhLdrqenQIYIwI8WDCPjbSaaO0fOBGgI/2rB+Q9pqoWiQFAdF+ 4ls0rq7q8zuoL6M7YLvhy1i08zy3VbeS/zGw8LPeLyfr1I3IxAjJwr4G+NllWiv+7MzW wn+QRqNJkgzv5WM1Go+Re7UfPD9jFAU6IeggmlqaKN+Y90LU2VZ6eoy0EVGeOxPKzn+q ilfA== X-Received: by 10.180.75.237 with SMTP id f13mr13162470wiw.69.1418815170789; Wed, 17 Dec 2014 03:19:30 -0800 (PST) Received: from [192.168.0.148] ([62.189.198.114]) by mx.google.com with ESMTPSA id pf4sm4680274wjb.36.2014.12.17.03.19.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 03:19:30 -0800 (PST) Message-ID: <549166B7.2030003@gmail.com> Date: Wed, 17 Dec 2014 11:19:19 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: 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> In-Reply-To: <5490E6F2.4050109@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][VOTE] Objects as Keys From: rowan.collins@gmail.com (Rowan Collins) 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. 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. Regards, -- Rowan Collins [IMSoP]