Re: [RFC] Iterable

From: Date: Sun, 03 Jul 2016 00:00:24 +0000
Subject: Re: [RFC] Iterable
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-94363@lists.php.net to get a copy of this message
Hi! > 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 I'm not sure I understand this part. Do you mean that this code: $a = json_decode('{"a": 1, "b": 2, "c": 3}'); foreach($a as $b) { var_dump($b); } will no longer work, or that it will still work, but stdClass would not be instanceof Iterable? -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#94363) next »