3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = array("A","B","C","D"); echo "Array current foreach value as variable expression:\n"; debug_zval_dump($list); foreach ( $list as $index => $var ) { echo "\nIteration #$index: "; debug_zval_dump($list); print(current($list)); } echo "\n\nArray current foreach value as function parameter\n"; debug_zval_dump($list); foreach ( $list as $var ) { echo "\nIteration #$index: "; print(item($list)); } function item($list) { debug_zval_dump($list); return current($list); } echo "\n\nArray as function parameter:\n"; item2($list); function item2($list) { debug_zval_dump($list); foreach ( $list as $var ) { echo "\nIteration #$index: "; debug_zval_dump($list); print(current($list)); } } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 36
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 20
filename:       /in/Cgr9U
function name:  (null)
number of ops:  42
compiled vars:  !0 = $list, !1 = $var, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    6     1        ECHO                                                     'Array+current+foreach+value+as+variable+expression%3A%0A'
    7     2        INIT_FCALL                                               'debug_zval_dump'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
    9     5      > FE_RESET_R                                       $5      !0, ->20
          6    > > FE_FETCH_R                                       ~6      $5, !1, ->20
          7    >   ASSIGN                                                   !2, ~6
   10     8        ROPE_INIT                                     3  ~9      '%0AIteration+%23'
          9        ROPE_ADD                                      1  ~9      ~9, !2
         10        ROPE_END                                      2  ~8      ~9, '%3A+'
         11        ECHO                                                     ~8
   11    12        INIT_FCALL                                               'debug_zval_dump'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
   12    15        INIT_FCALL                                               'current'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $12     
         18        ECHO                                                     $12
    9    19      > JMP                                                      ->6
         20    >   FE_FREE                                                  $5
   16    21        ECHO                                                     '%0A%0AArray+current+foreach+value+as+function+parameter%0A'
   17    22        INIT_FCALL                                               'debug_zval_dump'
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                                 
   19    25      > FE_RESET_R                                       $14     !0, ->36
         26    > > FE_FETCH_R                                               $14, !1, ->36
   20    27    >   ROPE_INIT                                     3  ~16     '%0AIteration+%23'
         28        ROPE_ADD                                      1  ~16     ~16, !2
         29        ROPE_END                                      2  ~15     ~16, '%3A+'
         30        ECHO                                                     ~15
   21    31        INIT_FCALL_BY_NAME                                       'item'
         32        SEND_VAR_EX                                              !0
         33        DO_FCALL                                      0  $18     
         34        ECHO                                                     $18
   19    35      > JMP                                                      ->26
         36    >   FE_FREE                                                  $14
   29    37        ECHO                                                     '%0A%0AArray+as+function+parameter%3A%0A'
   30    38        INIT_FCALL_BY_NAME                                       'item2'
         39        SEND_VAR_EX                                              !0
         40        DO_FCALL                                      0          
   41    41      > RETURN                                                   1

Function item:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Cgr9U
function name:  item
number of ops:  9
compiled vars:  !0 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'debug_zval_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   26     4        INIT_FCALL                                               'current'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   27     8*     > RETURN                                                   null

End of function item

Function item2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/Cgr9U
function name:  item2
number of ops:  20
compiled vars:  !0 = $list, !1 = $var, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'debug_zval_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   34     4      > FE_RESET_R                                       $4      !0, ->18
          5    > > FE_FETCH_R                                               $4, !1, ->18
   35     6    >   ROPE_INIT                                     3  ~6      '%0AIteration+%23'
          7        ROPE_ADD                                      1  ~6      ~6, !2
          8        ROPE_END                                      2  ~5      ~6, '%3A+'
          9        ECHO                                                     ~5
   36    10        INIT_FCALL                                               'debug_zval_dump'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
   37    13        INIT_FCALL                                               'current'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $9      
         16        ECHO                                                     $9
   34    17      > JMP                                                      ->5
         18    >   FE_FREE                                                  $4
   39    19      > RETURN                                                   null

End of function item2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.83 ms | 1404 KiB | 17 Q