3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_cyclic(&$array) { $isRecursive = false; set_error_handler(function ($errno, $errstr) use (&$isRecursive) { $isRecursive = $errno === E_WARNING && mb_stripos($errstr, 'recursion'); }); try { count($array, COUNT_RECURSIVE); } finally { restore_error_handler(); } return $isRecursive; } $array = [1, [2, 3]]; $array[1][1] = &$array; var_dump(is_cyclic($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OWbCE
function name:  (null)
number of ops:  11
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   17     1        FETCH_DIM_W                                      $2      !0, 1
          2        FETCH_DIM_W                                      $3      $2, 1
          3        ASSIGN_REF                                               $3, !0
   18     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'is_cyclic'
          6        SEND_REF                                                 !0
          7        DO_FCALL                                      0  $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function is_cyclic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 162) Position 1 = 13, Position 2 = 12
Branch analysis from position: 13
1 jumps found. (Code = 163) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OWbCE
function name:  is_cyclic
number of ops:  18
compiled vars:  !0 = $array, !1 = $isRecursive
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <false>
    5     2        INIT_FCALL                                               'set_error_handler'
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          4        BIND_LEXICAL                                             ~3, !1
    7     5        SEND_VAL                                                 ~3
    5     6        DO_ICALL                                                 
    9     7        INIT_FCALL                                               'count'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 1
         10        DO_ICALL                                                 
   10    11      > FAST_CALL                                                ->13
         12    > > JMP                                                      ->16
   11    13    >   INIT_FCALL                                               'restore_error_handler'
         14        DO_ICALL                                                 
         15      > FAST_RET                                                 
   13    16    > > RETURN                                                   !1
   14    17*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/OWbCE
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $errno, !1 = $errstr, !2 = $isRecursive
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
    6     3        IS_IDENTICAL                                     ~3      !0, 2
          4      > JMPZ_EX                                          ~3      ~3, ->10
          5    >   INIT_FCALL                                               'mb_stripos'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'recursion'
          8        DO_ICALL                                         $4      
          9        BOOL                                             ~3      $4
         10    >   ASSIGN                                                   !2, ~3
    7    11      > RETURN                                                   null

End of Dynamic Function 0

End of function is_cyclic

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.83 ms | 1463 KiB | 19 Q