Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23889 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15896 invoked by uid 1010); 3 Jun 2006 16:41:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 15881 invoked from network); 3 Jun 2006 16:41:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2006 16:41:10 -0000 X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:59395] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id C7/90-22639-5ABB1844 for ; Sat, 03 Jun 2006 12:41:10 -0400 Received: from baumbart.mbo (dslb-084-063-007-047.pools.arcor-ip.net [84.63.7.47]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id D23E535C1C1; Sat, 3 Jun 2006 18:41:06 +0200 (CEST) Date: Sat, 3 Jun 2006 18:43:26 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1895425731.20060603184326@marcus-boerger.de> To: Rasmus Lerdorf Cc: Ilia Alshanetsky , internals@lists.php.net, Dmitry Stogov , Andi Gutmans , Zeev Suraski In-Reply-To: <4481B92E.2030802@lerdorf.com> References: <795156743.20060603134212@marcus-boerger.de> <18CE805D-C032-4B64-950A-119E46287AF5@prohost.org> <4481B92E.2030802@lerdorf.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Missing __toString() part From: helly@php.net (Marcus Boerger) Hello Rasmus, though you are probably right here your idea brought to it's full extend will bring a major BC break. Just consider we had both key and value as a zval then the current behavior would change for quite a lot of situations including not only objects and resources but also booleans, floats and NULL. Right now everybody is used to the restiction that an array key can only be a string or an integer and if not it is either not acceptable as a key at all or is being converted to either one. best regards marcus Saturday, June 3, 2006, 6:30:38 PM, you wrote: > I don't understand why using the object as an index would trigger a > __toString() call. PHP's array indices are not defined to be strings, > so I don't see this as being a string context use and thus __toString() > shouldn't be called. > I also don't see why we need to make a distinction between the key and > the value here if there is any way we can avoid it. > For example, this obviously works: > class foo { > function a() { echo "a"; } > } > $a = new foo(); > $b[1] = $a; > $b[1]->a(); > Why shouldn't this? > $b[$a] = 1; > key($b)->a(); > I have always looked a PHP array as having 2 places to store things. > You can store stuff in the key with the caveat/feature that it must be > unique and you can store whatever you want in the value part. Only > allowing strings and integers in the key seems like an arbitrary > restriction to me. As long as the key is something we can somehow > uniquely identify I think we should aim to support it. > -Rasmus > Ilia Alshanetsky wrote: >> I think this is a potentially missing bit of functionality we definitely >> need to consider including. There is really no technical reason why >> $foo[new ToStringObject] = "bar"; cannot work or a reason why it >> shouldn't as far as functionality goes. >> >> >> Ilia Alshanetsky >> >> >> >> >> On 3-Jun-06, at 7:42 AM, Marcus Boerger wrote: >> >>> Hello guys, >>> >>> the attached patch closes one more __toString() part. It allows >>> to use objects that define __toString as indexes to arrays. What do >>> you guys think about this, should we add it or stay with the old >>> behavior that didn't allow objects as indexes at all. >>> >>> --Best regards, >>> Marcus mailto:mail@marcus-boerger.de >>> >>> --PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >> >> --PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php Best regards, Marcus