PHP Undefined index of array. Why?

arrays, php

Solution

I think, you are using a debug extension, so the `var_dump()` output is different then standart library, properties can not be numeric but `$obj->{'75'}` is okay. If can you reach to the sub object by `$items->{'75'}` yes you have a numeric property. otherwise you can try `print_r($items);` and see the original output, or check the array after `get_object_vars()`

    <?php

$items = new stdClass();
$items->{'75'} = new stdClass();
$items->{'75'}->{'85'} = new stdClass();


$items = (array) $items; // Casting unserialized stdClass to array
$items_array = get_object_vars($items); // getting object vars as an array.

var_dump($items["75"]); // Error
var_dump($items['75']); // Error
var_dump($items_array['75']); // Works

PHP issue : #45959

Read the casting blockquote: http://www.php.net/manual/en/language.types.array.php#language.types.array.casting

Problem

This is... I don't even know what this is happening. ``` // var_dump of items before object(stdClass)[84] public '75' => object(stdClass)[87] $items = (array) $items; // Casting unserialized stdClass to array var_dump($items); //Result of var dump: array '75' => object(stdClass)[87] //Now lets get this item: var_dump($items[75]); // Error var_dump($items['75']); // Error ``` What the? Thanks.

Original source

Related problems