3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class A { public $val; public function __construct($val) { $this->val = $val; } } $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)); $storage->rewind(); $iterated = 0; $expected = count($storage); while ($storage->valid()) { $iterated++; $object = $storage->current(); //echo $iterated . '(' . $object->val . ') - '; $storage->next(); foreach (range(1, 10) as $number) { if(rand(1,10) == $number) { // echo ' ' . $object->val . ' '; $storage->detach($object); unset($storage[$object]); continue; } } // echo PHP_EOL; } if(count($storage) != $expected) { echo 'Error!' . PHP_EOL; } exit;
Output for 5.3.4 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
Error!
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.2.15 - 5.2.17
Fatal error: Cannot use object of type SplObjectStorage as array in /in/tAtv4 on line 34
Process exited with code 255.