Let's say I have this array:
array(12) {
[0] =>
array(0) {
}
// [...]
[9] =>
string(5) "test"
[10] =>
array(0) {
}
[11] =>
class stdClass#5 (0) {
}
}
All items in this array where added like this $a[] = $somevalue.
Now I add another item: $a[] = new Foobar('bar');
However this results in:
array(13) {
[0] =>
array(0) {
}
// [...]
[9] =>
string(5) "test"
[10] =>
array(0) {
}
[11] =>
class stdClass#5 (0) {
}
[21] =>
class Foobar#8 (3) {
protected $id =>
string(11) "bar"
}
}
My Foobar object is not $a[12], why? Is there anything I can do such that PHP iterates properly?
Update:
I was not able to reproduce this behaviour in a single file. Unfortunately, a whole framework is involved in my code. As I'm only in control of the last statement ($a[] = new Foobar('id');), can I do something before that expression to force PHP to iterate properly?