3v4l.org

run code in 300+ PHP versions simultaneously
<?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)); $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; }
Output for git.master, git.master_jit, rfc.property-hooks
Iteration #1 with object A(1) Iteration #2 with object A(2) - deleted Object A(2) Iteration #3 with object A(1) Iteration #4 with object A(3) Iteration #5 with object A(4) Iteration #6 with object A(5) Iteration #7 with object A(6) Iteration #8 with object A(7) - deleted Object A(7) Iteration #9 with object A(1) Iteration #10 with object A(3) Iteration #11 with object A(4) Iteration #12 with object A(5) Iteration #13 with object A(6) Iteration #14 with object A(8) Iteration #15 with object A(9) Iteration #16 with object A(10) Error! - too much iterations!

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
42.62 ms | 402 KiB | 8 Q