3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public $val; public function __construct($val) { $this->val = $val; } } $storage = new SplObjectStorage; $expected = 10; // 10 iterations is expected, as storage has 10 objects attached for($i = 1; $i <= $expected; $i++) { $storage->attach(new A($i)); } $iterations = 0; $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; }
Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.19
Parse error: syntax error, unexpected '.' in /in/Jngul on line 24
Process exited with code 255.

preferences:
182.84 ms | 940 KiB | 56 Q