Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86658 invoked from network); 1 Feb 2013 00:05:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2013 00:05:31 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.128.179 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.128.179 mail-ve0-f179.google.com Received: from [209.85.128.179] ([209.85.128.179:58677] helo=mail-ve0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/50-14793-8C60B015 for ; Thu, 31 Jan 2013 19:05:29 -0500 Received: by mail-ve0-f179.google.com with SMTP id da11so1435919veb.10 for ; Thu, 31 Jan 2013 16:05:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=LeAK9lAp6twE9JDQwQ9I8iaGeFohq3XP60dUPSLgFtY=; b=nB/Bz5oPvPedSfUNFM7P+e9o6LHSdo40OI898Hjru7FPik9sa0CGeZyqFtxxN4R1O6 /KBmuitUDBGr7qiavkW6alSEgIUB3Y1+8doajOufOIGBerFLES0LVh++aydttVxEm5ZI O7MMchQc7JQooH6qPjwja3Ez43uFQC6LJg8O56Sh8j5q/Oi8yni6ulM4vCvIg12evvXp iDC19Ij5WMRPLvgZswINkUyDAizrVXGwmUHCk+zxPq69hm0wpAZxhewknTWLFguvgyix XNGGOV7GYndgTK3saQFwpmDWbTPndDmCo0zEJp83HCMF/dx9HWru0YFaNZIjBjjkQBFG kyMw== MIME-Version: 1.0 X-Received: by 10.52.175.106 with SMTP id bz10mr8431450vdc.125.1359677124944; Thu, 31 Jan 2013 16:05:24 -0800 (PST) Received: by 10.58.102.137 with HTTP; Thu, 31 Jan 2013 16:05:24 -0800 (PST) In-Reply-To: References: Date: Thu, 31 Jan 2013 19:05:24 -0500 Message-ID: To: Etienne Kneuss Cc: Anthony Ferrara , PHP internals Content-Type: multipart/alternative; boundary=bcaec5171e010aa3ca04d49e8053 X-Gm-Message-State: ALoCoQm9SYjZcP+zlQ5HWvJMjD0ffhtkFeR2nrE6GdvpjxLVLq9qsEnIgstCBOj1nnsccoiR247M Subject: Re: [PHP-DEV] rfc:foreach-non-scalar-keys From: rasmus@mindplay.dk (Rasmus Schultz) --bcaec5171e010aa3ca04d49e8053 Content-Type: text/plain; charset=ISO-8859-1 I'm not sure how I came to that conclusion - did the description change since I looked at it? I guess the title "foreach-non-scalar-keys" may have thrown me off - so this isn't about arrays, or really even about foreach, but about the Iterator interface. I'm not against that at all. I would suggest considering the addition of a second, distinct interface - rather than a modification to the existing interface, which already does what it's supposed to and works well, including the warning, which is appropriate for the intended use of that interface with the foreach statement. This alternative interface could have the opposite behavior - issuing a warning if the returned key is not an object. I don't think there's a legitimate use-case where mixing scalar and object keys would be a good idea? (if there were, a single interface might be the only way to go.) On Tue, Jan 29, 2013 at 8:34 AM, Etienne Kneuss wrote: > This RFC is not about arrays. > > The proposed change is to allow Iterator::key() to return things other > than int/strings. Consequently, it would mean foreach($iterable as > $key=>$foo) { $key can be an object here }. > > SplObjectStorage "solves" it by returning an array() of > object-key/object-data as *value*, and an integer as key, which is not > ideal. > > Best, > > > On Tue, Jan 29, 2013 at 2:15 PM, Anthony Ferrara wrote: > >> Rasmus, >> >> Relax. It hasn't even been proposed yet. Give the author some time to >> finish the RFC before proposing it here, and then we can discuss it... >> >> Anthony >> >> >> On Tue, Jan 29, 2013 at 8:03 AM, Rasmus Schultz >> wrote: >> >> > I just saw this RFC: >> > >> > https://wiki.php.net/rfc/foreach-non-scalar-keys >> > >> > By "non-scalar", presumably we're talking about objects? In the numbers >> > that e.g. resources typically get used, having a collection indexed by >> > resources would seem like an extremely exotic need. >> > >> > Moreover, we already have this: >> > >> > http://php.net/manual/en/class.splobjectstorage.php >> > >> > I just want to note that, while allowing non-scalar keys may seem like a >> > natural addition, we're not talking about a simple change to the foreach >> > statement - we're talking about a fundamental change to the array type. >> > >> > So I will point out two things: >> > >> > 1. Allowing non-scalar keys in arrays takes away an error-condition that >> > would normally be reported: accidentally using an object as a key (which >> > could even work in some cases, and could cause objects not to be garbage >> > collected.) >> > >> > 2. SplObjectStorage already solves this problem - minus e.g. resources, >> but >> > you could put your resources in an object and address that (very exotic) >> > need. >> > >> > Bottom line, I'm not in favor of this idea - it just doesn't seem >> necessary >> > or really even beneficial to me. >> > >> > - Rasmus Schultz >> > >> > > > > -- > Etienne Kneuss > http://www.colder.ch > --bcaec5171e010aa3ca04d49e8053--