3v4l.org

run code in 500+ PHP versions simultaneously
<?php $i = 0; function is_cyclic(array &$array) { global $i; // Exit when too deep. if (++$i > 10) exit; echo "Iteration $i:\n"; echo "Memory usage: " . memory_get_usage() . "\n"; 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 = [range(1, 1000), [range(1, 512), 3]]; $array[1][1] = &$array; return $array; } $bomb = craft_bomb(); is_cyclic($bomb);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k9s3V
function name:  (null)
number of ops:  8
compiled vars:  !0 = $i, !1 = $bomb
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 0
   45     1        INIT_FCALL                                                   'craft_bomb'
          2        DO_FCALL                                          0  $3      
          3        ASSIGN                                                       !1, $3
   46     4        INIT_FCALL                                                   'is_cyclic'
          5        SEND_REF                                                     !1
          6        DO_FCALL                                          0          
          7      > RETURN                                                       1

Function is_cyclic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 125) Position 1 = 37, Position 2 = 48
Branch analysis from position: 37
2 jumps found. (Code = 126) Position 1 = 38, Position 2 = 48
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 44
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 44
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
Branch analysis from position: 30
filename:       /in/k9s3V
function name:  is_cyclic
number of ops:  51
compiled vars:  !0 = $array, !1 = $i, !2 = $lastKey, !3 = $marker, !4 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
    7     1        BIND_GLOBAL                                                  !1, 'i'
   10     2        PRE_INC                                              ~5      !1
          3        IS_SMALLER                                                   10, ~5
          4      > JMPZ                                                         ~6, ->7
          5    > > INIT_FCALL                                                   'exit'
          6*       DO_ICALL                                                     
   12     7    >   ROPE_INIT                                         3  ~9      'Iteration+'
          8        ROPE_ADD                                          1  ~9      ~9, !1
          9        ROPE_END                                          2  ~8      ~9, '%3A%0A'
         10        ECHO                                                         ~8
   13    11        INIT_FCALL                                                   'memory_get_usage'
         12        DO_ICALL                                             $11     
         13        CONCAT                                               ~12     'Memory+usage%3A+', $11
         14        CONCAT                                               ~13     ~12, '%0A'
         15        ECHO                                                         ~13
   14    16        ECHO                                                         '%0A'
   16    17        INIT_FCALL                                                   'array_key_last'
         18        SEND_VAR                                                     !0
         19        DO_ICALL                                             $14     
         20        ASSIGN                                                       !2, $14
   17    21        TYPE_CHECK                                        2          !2
         22      > JMPZ                                                         ~16, ->24
   19    23    > > RETURN                                                       <false>
   21    24    >   BIND_STATIC                                                  !3
   22    25        TYPE_CHECK                                        2          !3
         26      > JMPZ                                                         ~17, ->30
   23    27    >   NEW                                                  $18     'stdClass'
         28        DO_FCALL                                          0          
         29        ASSIGN                                                       !3, $18
   25    30    >   FETCH_DIM_R                                          ~21     !0, !2
         31        IS_IDENTICAL                                                 !3, ~21
         32      > JMPZ                                                         ~22, ->34
   26    33    > > RETURN                                                       <true>
   28    34    >   ASSIGN_DIM                                                   !0
         35        OP_DATA                                                      !3
   29    36      > FE_RESET_RW                                          $24     !0, ->48
         37    > > FE_FETCH_RW                                                  $24, !4, ->48
   30    38    >   TYPE_CHECK                                      128  ~25     !4
         39      > JMPZ_EX                                              ~25     ~25, ->44
         40    >   INIT_FCALL_BY_NAME                                           'is_cyclic'
         41        SEND_VAR_EX                                                  !4
         42        DO_FCALL                                          0  $26     
         43        BOOL                                                 ~25     $26
         44    > > JMPZ                                                         ~25, ->47
   32    45    >   FE_FREE                                                      $24
         46      > RETURN                                                       <true>
   29    47    > > JMP                                                          ->37
         48    >   FE_FREE                                                      $24
   36    49      > RETURN                                                       <false>
   37    50*     > RETURN                                                       null

End of function is_cyclic

Function craft_bomb:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k9s3V
function name:  craft_bomb
number of ops:  18
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   INIT_FCALL                                                   'range'
          1        SEND_VAL                                                     1
          2        SEND_VAL                                                     1000
          3        DO_ICALL                                             $1      
          4        INIT_ARRAY                                           ~2      $1
          5        INIT_FCALL                                                   'range'
          6        SEND_VAL                                                     1
          7        SEND_VAL                                                     512
          8        DO_ICALL                                             $3      
          9        INIT_ARRAY                                           ~4      $3
         10        ADD_ARRAY_ELEMENT                                    ~4      3
         11        ADD_ARRAY_ELEMENT                                    ~2      ~4
         12        ASSIGN                                                       !0, ~2
   41    13        FETCH_DIM_W                                          $6      !0, 1
         14        FETCH_DIM_W                                          $7      $6, 1
         15        ASSIGN_REF                                                   $7, !0
   42    16      > RETURN                                                       !0
   43    17*     > RETURN                                                       null

End of function craft_bomb

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.46 ms | 1300 KiB | 19 Q