Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23901 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47331 invoked by uid 1010); 4 Jun 2006 01:50:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 47316 invoked from network); 4 Jun 2006 01:50:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2006 01:50:18 -0000 X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 204.11.219.139 lerdorf.com Linux 2.5 (sometimes 2.4) (4) Received: from ([204.11.219.139:34712] helo=lerdorf.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 89/C5-49656-85C32844 for ; Sat, 03 Jun 2006 21:50:17 -0400 Received: from [192.168.200.106] (c-24-6-5-134.hsd1.ca.comcast.net [24.6.5.134]) (authenticated bits=0) by lerdorf.com (8.13.6/8.13.6/Debian-1) with ESMTP id k541o9vw023542; Sat, 3 Jun 2006 18:50:11 -0700 Message-ID: <44823C51.7040408@lerdorf.com> Date: Sat, 03 Jun 2006 18:50:09 -0700 User-Agent: Thunderbird 3.0a1 (Macintosh/20060414) MIME-Version: 1.0 To: Alan Knowles CC: internals@lists.php.net References: <795156743.20060603134212@marcus-boerger.de> <20060603143639.GF5355@desario.homelinux.net> <509342741.20060603183859@marcus-boerger.de> <7.0.1.0.2.20060603175211.02208a50@zend.com> <20060604030100.1093d2f9@pierre-u64> <7.0.1.0.2.20060603181129.0396fc18@zend.com> <44823B41.5000608@akbkhome.com> In-Reply-To: <44823B41.5000608@akbkhome.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Missing __toString() part From: rasmus@lerdorf.com (Rasmus Lerdorf) Alan Knowles wrote: > > $x = new Obj; > $y[$x]= 123; > > That behaviour is going to be fun to document, and for people unfamilar > with it to find in the manual > -> php.net/array -> go to array syntax page -> read down to find about > objects as keys -> go to __toHash() page... > > ..whereas... > $x = new Obj; > $y[$x->toHash()]= 123; > > they might have a chance to see instantly how that is supposed to work, > on the rare occasion that somebody needs this, is it really worth > building it into the langauge???? In that case, why not just use the existing __toString explicitly with: $x = new Obj; $y[(string)$x] = 123; This works today and basically gives you the same thing. The only thing it doesn't do is separate an array index context from an output context allowing you do different things in the two cases. I think if we are going to add a toHash thing, it should trigger when the object is used in a hash context, just like toString triggers when it is used in a string context. -Rasmus