On Mon, 14 Jan 2019 at 11:57, Nikita Popov <nikita....@gmail.com> wrote:

> Rather than implementing Traversable, I think it would be much better to
> implement IteratorAggregate and provide a proper getIterator()
> implementation.


I think adding behaviour to stdClass is a precedent we should approach with
extreme caution.

Currently, it has no methods, and matches no type checks other than itself
and "object"; in a sense, it doesn't even have any properties, just the
ability to add them dynamically. To me, that makes sense: it's the
"classless object", the absolute bare minimum any object could be.



> What I mainly have in mind is that
> we should stop allowing iteration over arbitrary objects in the future (we
> did the first step by excluding them from "iterable") and instead require
> the use of an explicit PropertyIterator, or similar.


I agree that this should be explicit, and it could probably be implemented
as a very light wrapper.



> However, we'd probably still want to allow direct iteration of stdClass
>

Why? What do you consider the role of stdClass to be, that means having it
opt in to this behaviour would always be appropriate?

If you want something iterable, you can convert your stdClass object to an
array, wrap it an iterator that accepts any object, or convert it however
you want into a "proper" object where you can define what behaviour you
want.

Regards,
-- 
Rowan Collins
[IMSoP]

Reply via email to