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; for($i = 1; $i <= 10; $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) { $storage->detach($object); //echo ' - deleted Object A(' . $object->val . ') '; } //echo PHP_EOL; } echo 'Number of iterations: ' . $iterations . PHP_EOL;
Output for 5.1.0 - 5.6.28, 7.0.0 - 7.1.0
Number of iterations: 16
Output for hhvm-3.10.0 - 3.12.0
Number of iterations: 10
Output for 5.0.0 - 5.0.5
Fatal error: Class 'SplObjectStorage' not found in /in/VTRfW on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VTRfW on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VTRfW on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/VTRfW on line 4
Process exited with code 255.