Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Benjamin Morel
> `stdClass` can't die due to a lot of backwards compatibility in existing code (wordpress loves it) I, personally, would LOVE to see PHP break things on each release of a major version! I fail to see how upgrading could be painful, with a good changelog and the right E_DEPRECATED notices for a mi

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Marco Pivetta
On Mon, Jan 14, 2019 at 4:09 PM Benjamin Morel wrote: > > We should never have added stdClass. > > Why not deprecate it then, instead of extending it and giving it more > legitimacy? > This would remove some of the "2 ways of doing the same thing", such as > json_decode(). > > Ben > This. `std

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Benjamin Morel
> We should never have added stdClass. Why not deprecate it then, instead of extending it and giving it more legitimacy? This would remove some of the "2 ways of doing the same thing", such as json_decode(). Ben On Mon, 14 Jan 2019 at 16:00, Nikita Popov wrote: > On Mon, Jan 14, 2019 at 3:48

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Rowan Collins
On Mon, 14 Jan 2019 at 15:00, Nikita Popov wrote: > The way I see it, stdClass is basically an array in object notation (and > object passing semantics). It carries data in the form of key value pairs > and has no associated logic. The only things you can do with it are access > keys (properties)

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Nikita Popov
On Mon, Jan 14, 2019 at 3:48 PM Rowan Collins wrote: > On Mon, 14 Jan 2019 at 11:57, Nikita Popov wrote: > >> Rather than implementing Traversable, I think it would be much better to >> implement IteratorAggregate and provide a proper getIterator() >> implementation. > > > I think adding behavio

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Rowan Collins
On Mon, 14 Jan 2019 at 14:48, Rowan Collins wrote: > 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

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Rowan Collins
On Mon, 14 Jan 2019 at 13:23, Craig Duncan wrote: > What about an array is more iterable than a stdClass object? > An array is the structure PHP provides to represent a list, or an ordered collection of arbitrary key-value pairs; an object, whether stdClass or otherwise, is neither of these thi

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Rowan Collins
On Mon, 14 Jan 2019 at 11:57, Nikita Popov 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 cau

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Craig Duncan
On Sat, 12 Jan 2019 at 20:13, Dan Ackroyd wrote: > I think the correct long-term solution for this would be for us to > revisit the union type RFC (https://wiki.php.net/rfc/union_types) and > so be able to define a type like: > > type foreachable = object|iterable; > This argument makes sense to

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Craig Duncan
On Mon, 14 Jan 2019 at 11:57, Nikita Popov wrote: > Rather than implementing Traversable, I think it would be much better to > implement IteratorAggregate and provide a proper getIterator() > implementation. Objects that only implement Traversable are a PITA to work > with and lots of code assume

Re: [PHP-DEV] Making stdClass iterable

2019-01-14 Thread Nikita Popov
On Sat, Jan 12, 2019 at 8:39 PM Craig Duncan wrote: > Hi everybody > > I'd like to propose a change to stdClass so that it can satisfy the > iterable parameter/return type. > > Firstly I acknowledge that this isn't an ideal solution, but I think it > gets us to a better state than we're in today.

Re: [PHP-DEV] Making stdClass iterable

2019-01-12 Thread Markus Fischer
On 12.01.19 21:13, Dan Ackroyd wrote: Hi Duncan, [...] great points I was about to reply to Craig when Dans' email hit the list. I couldn't agree with Dan more. The expanded use of stdClass feels wrong to me, as in: wrong solution to a problem best solved differently. Dan gave ample exampl

Re: [PHP-DEV] Making stdClass iterable

2019-01-12 Thread Dan Ackroyd
Hi Duncan, I quite strongly dislike the idea, as it sounds like this solution is a hack for a particular use case, and that use case doesn't seem to be particularly important to me. I say it's not particularly important to me, as you could solve it right now by: i) asking json_decode to return a

[PHP-DEV] Making stdClass iterable

2019-01-12 Thread Craig Duncan
Hi everybody I'd like to propose a change to stdClass so that it can satisfy the iterable parameter/return type. Firstly I acknowledge that this isn't an ideal solution, but I think it gets us to a better state than we're in today. It shouldn't be necessary, but while we have such a common functi