3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $child; } function hasCycle($node) { $hare = $node; while ($node->child) { $node = $node->child; $hard = $hard->child->child; if ($node == $hare) { return true; } } return false; } function getLinkedList($length, $cycle = false) { $root = $node = new Node; $cycle_node = null; while ($length--) { $new_node = new Node; $node->child = $new_node; $node = $new_node; if ($cycle && $length == floor($length / 2)) { $cycle_node = $node; } } if ($cycle) { $node->child = $cycle_node; } return $root; } $cycled_list = getLinkedList(100, true); $list = getLinkedList(100, false); var_dump(has_cycle($cycled_list), has_cycle($list));
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function has_cycle() in /in/eECgf:51 Stack trace: #0 {main} thrown in /in/eECgf on line 51
Process exited with code 255.
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Fatal error: Call to undefined function has_cycle() in /in/eECgf on line 51
Process exited with code 255.

preferences:
201.14 ms | 402 KiB | 226 Q