PHP casting an object to an array

This just cost me a day. I had a JSON structure that I wanted in an array.
{
   "10": {
      "foo": "bar"
   },
   "20": {
      "baz": "fup"
  }
}
So the easiest way to do this (I thought) would be:
$content = (array)json_decode($some_json)
but I could not access any array element event though I could clearly see that the key existed
print_r($content[10]);
PHP Notice:  Undefined offset: ...
After slowly going insane I found a stackoverflow post that pointed to this
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: integer properties are unaccessible; 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:

This is fucking insane. Who comes up with this shit!?

Your rating: None Average: 5 (7 votes)