Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66193 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35101 invoked from network); 25 Feb 2013 14:58:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2013 14:58:41 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.181 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.181 mail-ob0-f181.google.com Received: from [209.85.214.181] ([209.85.214.181:41566] helo=mail-ob0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/39-10787-F1C7B215 for ; Mon, 25 Feb 2013 09:58:39 -0500 Received: by mail-ob0-f181.google.com with SMTP id ni5so2867744obc.40 for ; Mon, 25 Feb 2013 06:58:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=l9ko/6yQKzsy1xK9fFHGbhvWFP4tMrqekixArspu7N8=; b=hhHQQV8d54Ts2ULXNjVUIU0Y26/HLLQi0nOjO7W9Ulqa9LDzjhjWrPeSAvKesdTTLt WGk2jo9GCp9uViE4C3nkAT8j/AbYKnuNN7sKxqCsfwSRS44ELQOSU8cnnRl22QZf1bJm 9eDJYbs9tlLfHedTz+xZyymHA5SgAg25Xyc703A/0xGG8KuxkP2kfYFYfyTknM/Ywykf bg5vUsOj0EW53+mWBO/Tre28nAy19noEjaeyC2syyx0yVVXGYQHot93DPNG8/+BI7Uqu /qQ5ErAHkHpZYQ+bHNYuR3643EgKP8ABY9WXgP8vFpNsxagb5fgAu3YneEiXa5pFybUR WRsA== MIME-Version: 1.0 X-Received: by 10.60.170.20 with SMTP id ai20mr8085076oec.33.1361804316790; Mon, 25 Feb 2013 06:58:36 -0800 (PST) Received: by 10.182.49.136 with HTTP; Mon, 25 Feb 2013 06:58:36 -0800 (PST) In-Reply-To: References: Date: Mon, 25 Feb 2013 15:58:36 +0100 Message-ID: To: Etienne Kneuss Cc: Derick Rethans , PHP internals Content-Type: multipart/alternative; boundary=bcaec55409808e58eb04d68dc61c Subject: Re: [PHP-DEV] [RFC] Allow non-scalar keys in foreach From: nikita.ppv@gmail.com (Nikita Popov) --bcaec55409808e58eb04d68dc61c Content-Type: text/plain; charset=ISO-8859-1 On Tue, Feb 19, 2013 at 3:12 PM, Etienne Kneuss wrote: > > > > On Tue, Feb 19, 2013 at 2:55 PM, Derick Rethans wrote: > >> Gah, no top posting! >> >> On Tue, 19 Feb 2013, Etienne Kneuss wrote: >> >> > On Tue, Feb 19, 2013 at 2:25 PM, Derick Rethans wrote: >> > >> > > On Tue, 19 Feb 2013, Nikita Popov wrote: >> > > >> > > > This RFC proposes to remove the type-restrictions on Iterator keys >> > > > used in foreach: >> > > > >> > > > https://wiki.php.net/rfc/foreach-non-scalar-keys >> > > > >> > > > I took over Levi's RFC and added a patch for it. >> > > >> > > Under "Open Questions" you write: >> > > >> > > > What should be done with the keys that are valid in the iterator, >> > > > but not in the array? I think the best approach would be to just >> > > > set the array keys with the exact same semantics as PHP would do >> > > > (i.e. with all casts and warnings). >> > > >> > > Would __toString be called in case the key was an object? >> >> > I think the warning can stay as-is, __toString is not necessarily >> > available so casting to string in all occasions is probably not what >> > we want. >> >> I think it should cast to a string if possible. You are now making >> iterator_to_array not work with the new feature, and I find that a bit >> silly. Whether it should be __toString (or __toKey) I don't really care, >> but this new support for objects should be supported everywhere (and >> that includes iterator_to_array). >> > > I think this RFC is orthogonal to iterator_to_array supporting conversions > from objects to keys. > > $array[$obj] = 42; does not call __toString (or __toKey), it throws a > catchable fatal. IMO it would be inconsistent if iterator_to_array > gracefully accepted objects as keys. > I updated the patch to use the usual array assignment behavior. I.e. the behavior will be the same as the following code: function iterator_to_array($iter) { foreach ($iter as $k => $v) { $array[$k] = $v; } return $array; } I think it's reasonable to expect that the code will behave this way. If there are no objections I'd like to vote on this already on February 28th or March 1st. It is a few days shy of the 2 week discussion period, but I'd like to have this in 5.5 and the beta is tagged on the 7th already :) Nikita --bcaec55409808e58eb04d68dc61c--