PHP converting object to array

If an object is converted to an array, the result is an array whose elements are the object‘s properties. The keys are the member variable names, with a few notable exceptions: private variables have the class name prepended to the variable name; protected variables have a ‘*’ prepended to the variable name. These prepended values have null bytes on either side. This can result in some unexpected behaviour.

Source: http://www.php.net/manual/de/language.types.array.php#language.types.array.casting

No kidding? This must be one of the most stupid decisions ever in the whole language of PHP. Why pad some array keys with NULL BYTES? I mean, how can anyone ever be expected to find that out, by looking at the data the script writes out? This makes absolutely no sense whatsoever.

Just spent around an hour hunting this down!

I hope this post will save someone else the amount of hassle this has caused me.

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.