Arrays and stdClass Objects

This is just a note about arrays and how things can go wrong if not correctly setup.

The moral of the story, is don't do the following.

<?php
$array = Array();
$array->item[0]->value = "something";
?>

Even though these objects behave similar to arrays, you cannot initialize the array or object with Array() unless you are using $array as a real array.

The following would have worked.

<?php
$array->item[0]->value = "something";
?>

By the way, when I said real array, I meant using $array in the form $array['item'][0] = "something";.

I know this may not be clear and exactly kosher in terms of correct terminology -- I did my best. If you'd like more information, please write me. The email address is at the bottom of this page.

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.