On Tue, Feb 5, 2019 at 1:46 PM Rowan Collins <rowan.coll...@gmail.com> wrote:
> On Tue, 5 Feb 2019 at 17:25, Craig Duncan <p...@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. > > In other words, while stdClass CAN represent a plain array in cases where you've casted an array to an object: $c = (object)$array; there is nothing that says ALL instances of stdClass represent a plain array. At the point that the instance isn't representing an array, it's no more iterable than any other class that has properties. You can still iterate the public properties of a class though, even when is_iterable returns false. > 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] > -- -- Chase chasepee...@gmail.com