I am just trying to understand why the last two print_r()
calls below are not working and throws the following error Undefined property: stdClass::$0
. According to the PHP Documentation, I should be able to access the object numeric property using the the following operator $object->{'x'}
( x is the numeric index I want to access ).
Thanks.
$array = (object)array(
0 => 'test1',
1 => 'test2',
2 => 'test3',
'test' => (object)array(
0 => 'hi1',
1 => 'hi2',
2 => 'hi3'
)
);
print_r( $array );
print_r( $array->test );
print_r( $array->test->{'0'} );
print_r( $array->{'0'} );
die();
$array->{0} = 'test1'; print_r($array->{0});
int
indexes cannot be accessed this way it seems, later assigned string indexes can:$array->{'0'} = 'something';
& accessing that works, but makes a separate property from the0(int)
property...