3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(0, 1, 2); foreach ($arr as &$v) { $v += 1; } foreach ($arr as $v) { var_dump($v); } /* Output: int(1) int(2) int(2) Lines 2-4 iterate over $arr by reference. So, when we reach line 5, $v is still a reference to last element of the array (e.g. $v = &$arr[2]). There are only 2 possible ways to "unlink" $v from the array element: - use unset(): unset($v); - make $v a reference to another value: $v = &$x; Since $v is reference to last element of the array, the foreach loop in lines 5-7 will execute like this: 1) $v = $arr[0]; $arr is now [1, 2, 1], since writing to $v updates $arr[2] 2) $v = $arr[1]; $arr is now [1, 2, 2], since writing to $v updates $arr[2] 3) $v = $arr[2]; This causes self-assignment (e.g. $arr[2] = $arr[2]), which doesn't change the value of $arr. */
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 5
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 5
filename:       /in/Bi4c0
function name:  (null)
number of ops:  14
compiled vars:  !0 = $arr, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1      > FE_RESET_RW                                      $3      !0, ->5
          2    > > FE_FETCH_RW                                              $3, !1, ->5
    5     3    >   ASSIGN_OP                                     1          !1, 1
    4     4      > JMP                                                      ->2
          5    >   FE_FREE                                                  $3
    7     6      > FE_RESET_R                                       $5      !0, ->12
          7    > > FE_FETCH_R                                               $5, !1, ->12
    8     8    >   INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
    7    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $5
   34    13      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.25 ms | 1451 KiB | 14 Q