Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94361 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16141 invoked from network); 2 Jul 2016 14:39:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2016 14:39:36 -0000 Authentication-Results: pb1.pair.com header.from=aaron@trowski.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=aaron@trowski.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain trowski.com designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@trowski.com X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:64132] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/33-28154-722D7775 for ; Sat, 02 Jul 2016 10:39:36 -0400 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 401393BB9608; Sat, 2 Jul 2016 10:39:33 -0400 (EDT) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g557RS7EFWbv; Sat, 2 Jul 2016 10:39:32 -0400 (EDT) Received: from [10.0.1.3] (unknown [173.225.150.231]) by mercury.negativeion.net (Postfix) with ESMTPSA id A3E4E3BB95EB; Sat, 2 Jul 2016 10:39:32 -0400 (EDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_7CC2A985-4970-410A-9B56-8522CD9AAC8D" Message-ID: Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Date: Sat, 2 Jul 2016 09:39:26 -0500 References: <8284FE1F-70EE-4DB6-A945-0C57A4C99DCC@trowski.com> <16ef864f-8378-1af3-ddfb-21dc583a4b4a@gmx.de> <35132CB5-6E11-477F-8AC6-4374A7434D43@trowski.com> To: Jeremy Mikola , PHP internals In-Reply-To: X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] [RFC] Iterable From: aaron@trowski.com (Aaron Piotrowski) --Apple-Mail=_7CC2A985-4970-410A-9B56-8522CD9AAC8D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi Jeremy, > On Jun 30, 2016, at 3:01 PM, Jeremy Mikola wrote: >=20 > Was there any discussion about a special allowance being made for = stdClass? >=20 > I've noted the is_iterable(new stdClass) example and ensuing "Object = Iteration" section: >=20 > PHP allows any object to be used with foreach. However, iterable does = not accept any object, only those implementing Traversable. Values = accepted by iterable should be designed for iteration, not any set of = values (such as the public properties of an object or a string). >=20 > I'm on the fence if that second sentence applies to stdClass. Based on = how users typically end up with stdClass instances (e.g. casting arrays = to an object, json_decode()), I tend to think of them as logically = equivalent to associative arrays. To that end, I'd consider stdClass to = be as "designed for iteration" as any associative array -- if we can = even say a stdClass was designed at all :) >=20 > As-is, the RFC requires users to either cast stdClass instances to an = array or decorate them with an Iterator (e.g. ArrayObject). I find this = a bit irksome, but it's certainly easy to work around. >=20 > That said, I realize that voting is in progress and it's not my = intention to interrupt anything. I just wanted to relay a viewpoint that = might not have come up. >=20 Generally when I've seen an object that did not implement Traversable = used with foreach it has been an error. The exception of course is = stdClass, particularly because of json_decode(). There was no discussion = on the list of allowing stdClass, but I did discuss it with some people = in chat. Our consensus was that a casting to an array was a reasonable = and simple requirement to allow an instance of stdClass to be iterable. = I do not think stdClass was designed for iteration, but rather is just = used this way because of the behavior of foreach. I'd prefer = json_decode() to return an iterable object... maybe an RFC for another = day. Aaron Piotrowski= --Apple-Mail=_7CC2A985-4970-410A-9B56-8522CD9AAC8D--