Skip to content

EntityIterator bugged on Unset #15

Closed
@Swader

Description

@Swader

When unsetting some elements in the EntityIterator, the next iteration over it will be bugged in that it will only go through some of the elements. Example code for reproduction (dump is from Symfony VarDumper, use var_dump if you don't have it installed):

$a = range(1, 30);
$r = new Response(200);
$ei = new EntityIterator($a, $r);

dump('First run');
foreach ($ei as $i) {
    dump($i);
}

dump('Second run');
foreach ($ei as $i) {
    dump($i);
}

dump($ei);

foreach ($ei as $index => $element) {
    if ($element % 3 === 0) {
        dump("Unsetting " . $element . ' at index ' . $index);
        unset($ei[$index]);
    }
}

dump($ei);

dump('Third run');
foreach ($ei as $i) {
    dump($i);
}

The first and second loop display all 30 elements. The third loop unsets multiples of 3. The fourth loop then only loops as far as number 23, but no further.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions