3v4l.org

run code in 500+ PHP versions simultaneously
<?php $x = [1,2,3]; foreach($x as &$ref){ $ref += 100; } /* $x === [101, 102, 103] at this point, $ref is bound to the last element of $x, that's OK */ $b = $x; /* this should logically copy $x to $b *by value* (COW happens) */ $b[0] = 0; /* this should force an array copy in memory */ /* here, $ref should be rebound to the elements of $x by reference */ foreach($x as &$ref){ $ref += 100; } /* at this point, $x === [201, 202, 203] which is correct, $ref refers to the last element of $x again, which is OK, BUT! As we copied $b by value before, is should stay as is, but the last element of $b changes to 203! */ var_dump($b);
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 = 125) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 126) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 5
filename:       /in/q3MhC
function name:  (null)
number of ops:  18
compiled vars:  !0 = $x, !1 = $ref, !2 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    3     1      > FE_RESET_RW                                          $4      !0, ->5
          2    > > FE_FETCH_RW                                                  $4, !1, ->5
    4     3    >   ASSIGN_OP                                         1          !1, 100
    3     4      > JMP                                                          ->2
          5    >   FE_FREE                                                      $4
   11     6        ASSIGN                                                       !2, !0
   14     7        ASSIGN_DIM                                                   !2, 0
          8        OP_DATA                                                      0
   18     9      > FE_RESET_RW                                          $8      !0, ->13
         10    > > FE_FETCH_RW                                                  $8, !1, ->13
   19    11    >   ASSIGN_OP                                         1          !1, 100
   18    12      > JMP                                                          ->10
         13    >   FE_FREE                                                      $8
   28    14        INIT_FCALL                                                   'var_dump'
         15        SEND_VAR                                                     !2
         16        DO_ICALL                                                     
         17      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
151.78 ms | 2009 KiB | 9 Q