3v4l.org

run code in 300+ PHP versions simultaneously
<?php $refs = array(); function wrap( $arr){ // Need to clear out the global references array, I chose to do this here global $refs; $refs = array(); test( $arr); } function test( $arr){ global $refs; foreach( $arr as $v) { if( $v === $arr || in_array( $v, $refs)) { print ' ref '; $refs[] = $v; } else { if( is_array( $v)) { test( $v); } else { print $v . ', '; } } } } echo "Array 1:\n"; $array1 = array(1, 2, 3); $array1[4] = &$array1; wrap( $array1); echo "\nArray 2:\n"; $array2 = array(1, 2, 3, array(1, 2, 3)); $array2[2] = &$array2; wrap( $array2); echo "\nArray 3:\n"; $array3 = array(1, 2, 3, array(1, 2, 3)); $array3[3][1] = &$array3; wrap( $array3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f0oET
function name:  (null)
number of ops:  24
compiled vars:  !0 = $refs, !1 = $array1, !2 = $array2, !3 = $array3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   27     1        ECHO                                                     'Array+1%3A%0A'
   28     2        ASSIGN                                                   !1, <array>
   29     3        FETCH_DIM_W                                      $6      !1, 4
          4        ASSIGN_REF                                               $6, !1
   30     5        INIT_FCALL                                               'wrap'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0          
   32     8        ECHO                                                     '%0AArray+2%3A%0A'
   33     9        ASSIGN                                                   !2, <array>
   34    10        FETCH_DIM_W                                      $10     !2, 2
         11        ASSIGN_REF                                               $10, !2
   35    12        INIT_FCALL                                               'wrap'
         13        SEND_VAR                                                 !2
         14        DO_FCALL                                      0          
   37    15        ECHO                                                     '%0AArray+3%3A%0A'
   38    16        ASSIGN                                                   !3, <array>
   39    17        FETCH_DIM_W                                      $14     !3, 3
         18        FETCH_DIM_W                                      $15     $14, 1
         19        ASSIGN_REF                                               $15, !3
   40    20        INIT_FCALL                                               'wrap'
         21        SEND_VAR                                                 !3
         22        DO_FCALL                                      0          
         23      > RETURN                                                   1

Function wrap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f0oET
function name:  wrap
number of ops:  7
compiled vars:  !0 = $arr, !1 = $refs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        BIND_GLOBAL                                              !1, 'refs'
    7     2        ASSIGN                                                   !1, <array>
    8     3        INIT_FCALL_BY_NAME                                       'test'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
    9     6      > RETURN                                                   null

End of function wrap

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/f0oET
function name:  test
number of ops:  27
compiled vars:  !0 = $arr, !1 = $refs, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        BIND_GLOBAL                                              !1, 'refs'
   13     2      > FE_RESET_R                                       $3      !0, ->25
          3    > > FE_FETCH_R                                               $3, !2, ->25
   14     4    >   IS_IDENTICAL                                     ~4      !2, !0
          5      > JMPNZ_EX                                         ~4      ~4, ->11
          6    >   INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $5      
         10        BOOL                                             ~4      $5
         11    > > JMPZ                                                     ~4, ->16
   15    12    >   ECHO                                                     '+ref+'
   16    13        ASSIGN_DIM                                               !1
         14        OP_DATA                                                  !2
         15      > JMP                                                      ->24
   18    16    >   TYPE_CHECK                                  128          !2
         17      > JMPZ                                                     ~7, ->22
   19    18    >   INIT_FCALL_BY_NAME                                       'test'
         19        SEND_VAR_EX                                              !2
         20        DO_FCALL                                      0          
         21      > JMP                                                      ->24
   21    22    >   CONCAT                                           ~9      !2, '%2C+'
         23        ECHO                                                     ~9
   13    24    > > JMP                                                      ->3
         25    >   FE_FREE                                                  $3
   25    26      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.78 ms | 1403 KiB | 18 Q