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; $refs[] = $arr; foreach( $arr as $v) { if( in_array( $v, $refs)) { print ' ref '; } 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/WMZBS
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/WMZBS
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 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 22
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/WMZBS
function name:  test
number of ops:  24
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        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  !0
   14     4      > FE_RESET_R                                       $4      !0, ->22
          5    > > FE_FETCH_R                                               $4, !2, ->22
   15     6    >   INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $5      
         10      > JMPZ                                                     $5, ->13
   16    11    >   ECHO                                                     '+ref+'
         12      > JMP                                                      ->21
   18    13    >   TYPE_CHECK                                  128          !2
         14      > JMPZ                                                     ~6, ->19
   19    15    >   INIT_FCALL_BY_NAME                                       'test'
         16        SEND_VAR_EX                                              !2
         17        DO_FCALL                                      0          
         18      > JMP                                                      ->21
   21    19    >   CONCAT                                           ~8      !2, '%2C+'
         20        ECHO                                                     ~8
   14    21    > > JMP                                                      ->5
         22    >   FE_FREE                                                  $4
   25    23      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.75 ms | 1403 KiB | 18 Q