Hacker News new | ask | show | jobs
by paledot 2159 days ago
> Important to notice that casting an array with numeric keys into an object is valid, but one can't dereference its value because property names may not start with numbers.

Not true, actually. The (admittedly obscure) syntax to access a property beginning with a numeral is `$obj->{0}`. Usually when this happens it's because someone was trying to be clever with JSON.

1 comments

There's another way to get a variable starting with a numeral - abusing extract(), I think.
I've seen a few workarounds, each worse than the last, including casting back to array, round-tripping through JSON with the array flag set, and reflection. Hence the public service announcement that this is perfectly doable with the correct syntax.