3v4l.org

run code in 300+ PHP versions simultaneously
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); <?php $myArray = new ArrayObject( "a", new ArrayObject( "a", "b", new ArrayObject( "a", "b", "c", new ArrayObject( "a", "b", "c", "d", new ArrayObject("the end") ) ) ) ); $recursive_array_iterator = new RecursiveArrayIterator($myArray); iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); function traverseRecursiveArray($iterator) { $i = 0; while ($iterator->valid()) { if ($iterator->hasChildren()) { traverseRecursiveArray($iterator->getChildren()); } else { $iterator->offsetSet($iterator->key(), manipulate($iterator->current())); echo $iterator->key() . ' => ' . $iterator->current() . PHP_EOL; } $iterator->next(); } } function manipulate($string) { $string .= " appended"; return $string; } var_dump($myArray);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Uncaught TypeError: ArrayObject::__construct(): Argument #1 ($array) must be of type array, string given in /in/aa57I:18 Stack trace: #0 /in/aa57I(18): ArrayObject->__construct('the end') #1 {main} thrown in /in/aa57I on line 18
Process exited with code 255.
Output for 7.0.18 - 7.0.33, 7.1.4 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object in /in/aa57I:18 Stack trace: #0 /in/aa57I(18): ArrayObject->__construct('the end') #1 {main} thrown in /in/aa57I on line 18
Process exited with code 255.
Output for 7.0.0 - 7.0.17, 7.1.0 - 7.1.3
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Uncaught InvalidArgumentException: Passed variable is not an array or object, using empty array instead in /in/aa57I:18 Stack trace: #0 /in/aa57I(18): ArrayObject->__construct('the end') #1 {main} thrown in /in/aa57I on line 18
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in /in/aa57I:18 Stack trace: #0 /in/aa57I(18): ArrayObject->__construct('the end') #1 {main} thrown in /in/aa57I on line 18
Process exited with code 255.
Output for 5.0.5
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Uncaught exception 'Exception' with message 'Passed variable is not an array or object, using empty array instead' in /in/aa57I:18 Stack trace: #0 /in/aa57I(18): ArrayObject->__construct('the end') #1 {main} thrown in /in/aa57I on line 18
Process exited with code 255.
Output for 5.0.4
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Uncaught exception 'Exception' with message 'Passed variable is not an array or object, using empty array instead' in /in/aa57I:18 Stack trace: #0 /in/aa57I(18): ArrayObject->__construct() #1 {main} thrown in /in/aa57I on line 18
Process exited with code 255.
Output for 5.0.0 - 5.0.3
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Warning: ArrayObject::__construct(): Passed variable is not an array or object, using empty array instead in /in/aa57I on line 18 Warning: Wrong parameter count for __construct() in /in/aa57I on line 19 Warning: Wrong parameter count for __construct() in /in/aa57I on line 20 Warning: Wrong parameter count for __construct() in /in/aa57I on line 21 Warning: Wrong parameter count for __construct() in /in/aa57I on line 22 Fatal error: Class 'RecursiveArrayIterator' not found in /in/aa57I on line 24
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Cannot instantiate non-existent class: arrayobject in /in/aa57I on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
iterator_apply($recursive_array_iterator, 'traverseRecursiveArray', array($recursive_array_iterator)); Fatal error: Cannot instantiate non-existent class: arrayobject in /in/aa57I on line 4

preferences:
274.26 ms | 402 KiB | 459 Q