3v4l.org

run code in 300+ PHP versions simultaneously
<?php $i = 0; function is_cyclic(array &$array) { global $i; // Exit when too deep. if (++$i > 10) exit; echo "Call $i:\n"; var_dump($GLOBALS['bomb']); echo "\n"; $lastKey = array_key_last($array); if ($lastKey === null) { // Array is empty return false; } static $marker; if ($marker === null) $marker = new stdClass(); if ($array[$lastKey] === $marker) { return true; } $array[] = $marker; foreach ($array as &$item) { if (is_array($item) && is_cyclic($item)) { //array_pop($array); return true; } } //array_pop($array); return false; } function craft_bomb() { $array = [1, [2, 3]]; $array[1][1] = &$array; return $array; } $bomb = craft_bomb(); is_cyclic($bomb);
Output for git.master, git.master_jit, rfc.property-hooks
Call 1: array(2) { [0]=> int(1) [1]=> array(2) { [0]=> int(2) [1]=> *RECURSION* } } Call 2: array(3) { [0]=> int(1) [1]=> &array(2) { [0]=> int(2) [1]=> array(2) { [0]=> int(1) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } Call 3: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(2) { [0]=> int(1) [1]=> array(2) { [0]=> int(2) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 4: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(2) { [0]=> int(2) [1]=> array(2) { [0]=> int(1) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 5: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(2) { [0]=> int(1) [1]=> array(2) { [0]=> int(2) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 6: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(2) { [0]=> int(2) [1]=> array(2) { [0]=> int(1) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 7: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(2) { [0]=> int(1) [1]=> array(2) { [0]=> int(2) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 8: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(2) { [0]=> int(2) [1]=> array(2) { [0]=> int(1) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 9: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(2) { [0]=> int(1) [1]=> array(2) { [0]=> int(2) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } Call 10: array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(3) { [0]=> int(2) [1]=> &array(3) { [0]=> int(1) [1]=> &array(2) { [0]=> int(2) [1]=> array(2) { [0]=> int(1) [1]=> *RECURSION* } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } } [2]=> object(stdClass)#1 (0) { } }

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:
68.41 ms | 417 KiB | 8 Q