This is an error 404
There are `0` results
preferences:
171.77 ms | 944 KiB | 8 Q<?php
class A
{
public $val;
public function __construct($val) { $this->val = $val; }
public function rewind()
{
echo __METHOD__;
parent::rewind();
}
}
$storage = new SplObjectStorage;
$storage->attach(new A(1));
$storage->attach(new A(2));
$storage->attach(new A(3));
$storage->attach(new A(4));
$storage->attach(new A(5));
$storage->attach(new A(6));
$storage->attach(new A(7));
$storage->attach(new A(8));
$storage->attach(new A(9));
$storage->attach(new A(10));
$iterations = 0;
$expected = 10; // 10 iterations is expected, as storage has 10 objects attached
$storage->rewind();
while ($storage->valid()) {
$iterations++;
$object = $storage->current();
echo 'Iteration #' . $iterations . ' with object A(' . $object->val . ')';
$storage->next();
if($iterations === 2 || $iterations === 8) {
echo ' - deleted Object A(' . $object->val . ') ' . PHP_EOL;
$storage->detach($object);
continue;
}
echo PHP_EOL;
}
if(count($storage) != $iterations) {
echo 'Error! - too much iterations!' . PHP_EOL;
} else {
echo 'Success - there was 10 iterations as expected.' . PHP_EOL;
}