3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $bar = ""; } $foos = ['a' => new Foo()]; $foos['b'] = &$foos['a']; function modifyFoos(array $foos) { $foos['a']->bar = "bar"; } modifyFoos($foos); var_dump($foos); function modifyFoosHandlingReferencesIncorrectly(array $foos) { foreach ($foos as $key => $val) { $foos[$key] = clone $val; } $foos['a']->bar = "baz"; var_dump($foos); } modifyFoosHandlingReferencesIncorrectly($foos); var_dump($foos); function modifyFoosHandlingReferences(array $foos) { $oldFoos = $foos; $foos = []; foreach ($oldFoos as $key => $val) { $foos[$key] = clone $val; } $foos['a']->bar = "barbaz"; } modifyFoosHandlingReferences($foos); var_dump($foos);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tNYYj
function name:  (null)
number of ops:  27
compiled vars:  !0 = $foos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   NEW                                              $1      'Foo'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~3      $1, 'a'
          3        ASSIGN                                                   !0, ~3
    9     4        FETCH_DIM_W                                      $6      !0, 'a'
          5        MAKE_REF                                         $7      $6
          6        FETCH_DIM_W                                      $5      !0, 'b'
          7        ASSIGN_REF                                               $5, $7
   16     8        INIT_FCALL                                               'modifyfoos'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0          
   18    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
   29    14        INIT_FCALL                                               'modifyfooshandlingreferencesincorrectly'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0          
   31    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
   43    20        INIT_FCALL                                               'modifyfooshandlingreferences'
         21        SEND_VAR                                                 !0
         22        DO_FCALL                                      0          
   45    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Function modifyfoos:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tNYYj
function name:  modifyFoos
number of ops:  5
compiled vars:  !0 = $foos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        FETCH_DIM_W                                      $1      !0, 'a'
          2        ASSIGN_OBJ                                               $1, 'bar'
          3        OP_DATA                                                  'bar'
   14     4      > RETURN                                                   null

End of function modifyfoos

Function modifyfooshandlingreferencesincorrectly:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/tNYYj
function name:  modifyFoosHandlingReferencesIncorrectly
number of ops:  16
compiled vars:  !0 = $foos, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1      > FE_RESET_R                                       $3      !0, ->8
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->8
          3    >   ASSIGN                                                   !2, ~4
   23     4        CLONE                                            ~7      !1
          5        ASSIGN_DIM                                               !0, !2
          6        OP_DATA                                                  ~7
   22     7      > JMP                                                      ->2
          8    >   FE_FREE                                                  $3
   25     9        FETCH_DIM_W                                      $8      !0, 'a'
         10        ASSIGN_OBJ                                               $8, 'bar'
         11        OP_DATA                                                  'baz'
   26    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
   27    15      > RETURN                                                   null

End of function modifyfooshandlingreferencesincorrectly

Function modifyfooshandlingreferences:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/tNYYj
function name:  modifyFoosHandlingReferences
number of ops:  15
compiled vars:  !0 = $foos, !1 = $oldFoos, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   35     1        ASSIGN                                                   !1, !0
   36     2        ASSIGN                                                   !0, <array>
   37     3      > FE_RESET_R                                       $6      !1, ->10
          4    > > FE_FETCH_R                                       ~7      $6, !2, ->10
          5    >   ASSIGN                                                   !3, ~7
   38     6        CLONE                                            ~10     !2
          7        ASSIGN_DIM                                               !0, !3
          8        OP_DATA                                                  ~10
   37     9      > JMP                                                      ->4
         10    >   FE_FREE                                                  $6
   40    11        FETCH_DIM_W                                      $11     !0, 'a'
         12        ASSIGN_OBJ                                               $11, 'bar'
         13        OP_DATA                                                  'barbaz'
   41    14      > RETURN                                                   null

End of function modifyfooshandlingreferences

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.08 ms | 1407 KiB | 18 Q