graze / dal

Data Access Layer
MIT License
8 stars 0 forks source link

detach() freaks the internal pointer out, so cannot be used within foreach #8

Closed john-n-smith closed 10 years ago

john-n-smith commented 10 years ago

It seems to try to set the internal pointer to 1

$spl = new SplObjectStorage();

$n = 4;

for($i=0; $i < $n; $i++) {
  $object = new StdClass;
  $spl->attach($object);
}
foreach($spl as $object) {
    echo $spl->key() . '<br>';
    $spl->detach($object);
}

results in

0
1
1

n = 3:

0
1

n = 2:

0
adlawson commented 10 years ago

Good bug finding!