3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $refs = array(); function wrap( $arr){ // Need to clear out the global references array, I chose to do this here global $refs; $refs = array(); test( $arr); } function test( $arr){ global $refs; $refs[] = $arr; foreach( $arr as $v) { if( in_array( $v, $refs)) { print ' ref '; } else { if( is_array( $v)) { test( $v); } else { print $v . ', '; } } } } echo "Array 1:\n"; $array1 = array(1, 2, 3); $array1[4] = &$array1; wrap( $array1); echo "\nArray 2:\n"; $array2 = array(1, 2, 3, array(1, 2, 3)); $array2[2] = &$array2; wrap( $array2); echo "\nArray 3:\n"; $array3 = array(1, 2, 3, array(1, 2, 3)); $array3[3][1] = &$array3; wrap( $array3);
Output for 5.3.15 - 5.3.29, 5.4.5 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array 1: 1, 2, 3, ref Array 2: 1, 2, ref 1, 2, 3, Array 3: 1, 2, 3, 1, ref 3,
Output for 5.2.3 - 5.3.14, 5.4.0 - 5.4.4
Array 1: 1, 2, 3, Fatal error: Nesting level too deep - recursive dependency? in /in/WMZBS on line 15
Process exited with code 255.
Output for 4.3.2 - 5.2.2
Array 1: 1, 2, 3, <br /> <b>Fatal error</b>: Nesting level too deep - recursive dependency? in <b>/in/WMZBS</b> on line <b>15</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Array 1: 1, 2, 3, <br /> <b>Fatal error</b>: Nesting level too deep - recursive dependency? in <b>/in/WMZBS</b> on line <b>15</b><br />