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));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eECgf
function name:  (null)
number of ops:  21
compiled vars:  !0 = $cycled_list, !1 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   INIT_FCALL                                               'getlinkedlist'
          1        SEND_VAL                                                 100
          2        SEND_VAL                                                 <true>
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   48     5        INIT_FCALL                                               'getlinkedlist'
          6        SEND_VAL                                                 100
          7        SEND_VAL                                                 <false>
          8        DO_FCALL                                      0  $4      
          9        ASSIGN                                                   !1, $4
   51    10        INIT_FCALL                                               'var_dump'
         11        INIT_FCALL_BY_NAME                                       'has_cycle'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR                                                 $6
         15        INIT_FCALL_BY_NAME                                       'has_cycle'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $7      
         18        SEND_VAR                                                 $7
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function hascycle:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/eECgf
function name:  hasCycle
number of ops:  15
compiled vars:  !0 = $node, !1 = $hare, !2 = $hard
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        ASSIGN                                                   !1, !0
   11     2      > JMP                                                      ->11
   12     3    >   FETCH_OBJ_R                                      ~4      !0, 'child'
          4        ASSIGN                                                   !0, ~4
   13     5        FETCH_OBJ_R                                      ~6      !2, 'child'
          6        FETCH_OBJ_R                                      ~7      ~6, 'child'
          7        ASSIGN                                                   !2, ~7
   15     8        IS_EQUAL                                                 !0, !1
          9      > JMPZ                                                     ~9, ->11
   16    10    > > RETURN                                                   <true>
   11    11    >   FETCH_OBJ_R                                      ~10     !0, 'child'
         12      > JMPNZ                                                    ~10, ->3
   20    13    > > RETURN                                                   <false>
   21    14*     > RETURN                                                   null

End of function hascycle

Function getlinkedlist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 8
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 8
Branch analysis from position: 25
Branch analysis from position: 8
Branch analysis from position: 23
Branch analysis from position: 21
filename:       /in/eECgf
function name:  getLinkedList
number of ops:  30
compiled vars:  !0 = $length, !1 = $cycle, !2 = $root, !3 = $node, !4 = $cycle_node, !5 = $new_node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
   26     2        NEW                                              $6      'Node'
          3        DO_FCALL                                      0          
          4        ASSIGN                                           ~8      !3, $6
          5        ASSIGN                                                   !2, ~8
   27     6        ASSIGN                                                   !4, null
   29     7      > JMP                                                      ->23
   30     8    >   NEW                                              $11     'Node'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !5, $11
   31    11        ASSIGN_OBJ                                               !3, 'child'
         12        OP_DATA                                                  !5
   32    13        ASSIGN                                                   !3, !5
   34    14      > JMPZ_EX                                          ~16     !1, ->21
         15    >   INIT_FCALL                                               'floor'
         16        DIV                                              ~17     !0, 2
         17        SEND_VAL                                                 ~17
         18        DO_ICALL                                         $18     
         19        IS_EQUAL                                         ~19     !0, $18
         20        BOOL                                             ~16     ~19
         21    > > JMPZ                                                     ~16, ->23
   35    22    >   ASSIGN                                                   !4, !3
   29    23    >   POST_DEC                                         ~21     !0
         24      > JMPNZ                                                    ~21, ->8
   39    25    > > JMPZ                                                     !1, ->28
   40    26    >   ASSIGN_OBJ                                               !3, 'child'
         27        OP_DATA                                                  !4
   43    28    > > RETURN                                                   !2
   44    29*     > RETURN                                                   null

End of function getlinkedlist

Class Node: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.88 ms | 1394 KiB | 19 Q