3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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.2.0
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.3.18 - 5.6.28
Fatal error: Call to undefined function has_cycle() in /in/eECgf on line 51
Process exited with code 255.