Re: [VOTE] Making stdClass iterable

From: Date: Tue, 05 Feb 2019 18:46:37 +0000
Subject: Re: [VOTE] Making stdClass iterable
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-104208@lists.php.net to get a copy of this message
On Tue, 5 Feb 2019 at 17:25, Craig Duncan <php@duncanc.co.uk> wrote: > The *iterable* type accepts a plain array, but not an object that is used > to represent a plain array, that's surprising to me. > I think this notion of stdClass as "an object used to represent a plain array" is a peculiar one. The only reason I can think of for using stdClass is to specifically *not* be like an array in some way. As I mentioned in the discussion thread, the closer comparison would be to an anonymous class: $foo = new stdClass; and $foo = new class {}; both produce objects with no behaviour, no pre-defined methods, and the ability to define properties dynamically. On that definition, there's no surprise at all: it's an object that has no defined behaviour, so is not defined as having the "iterable" behaviour. > To me, this class is presented as a first class citizen, but it works like > a second class one. > While I agree that it's an anomaly in many ways, I think the fact that it's not marked iterable is a peculiar detail to get stuck on. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#104208) next »