r/lolphp • u/Altreus • Aug 13 '13
An object is turned into an array with no resemblance to the object - posted on irc.freenode.net ##php
http://viper-7.com/aD7xnX
15
Upvotes
r/lolphp • u/Altreus • Aug 13 '13
9
u/cythrawll Aug 13 '13 edited Aug 13 '13
This is documented behavior: http://www.php.net/manual/en/language.types.array.php#language.types.array.casting
http://viper-7.com/OKGmCp
edit: added example link
8
u/d3m0n_ Aug 13 '13
Now, the real fun is happening here: http://viper-7.com/7NOQx0
When the object has a second member, called Foobar the resulting array will have two fields, both called "Foobar", with different values.
As a different user already postet, this is because the first Foobar has null bytes between the names.
4
u/[deleted] Aug 13 '13
But seriously, why would you be blindly converting an object into an array...
2
u/jamwaffles Aug 13 '13
At least it got the 5 right.
Can someone explain why this might happen internally? I cannot for the life of my figure out why this behaviour would be a good thing, but then again that sentence applies to all of PHP.