3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $bar = ""; } $fooArr = [new Foo()]; function modifiesLocallyClonedFoo($fooArr) { $fooArr[0] = clone $fooArr[0]; $fooArr[0]->bar = "bar"; } modifiesLocallyClonedFoo($fooArr); var_dump($fooArr[0]); // Creating a reference to an array item changes the way the array behaves?!?!?!? $bar = &$fooArr[0]; modifiesLocallyClonedFoo($fooArr); var_dump($fooArr[0]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G1VRc
function name:  (null)
number of ops:  21
compiled vars:  !0 = $fooArr, !1 = $bar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   NEW                                              $2      'Foo'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~4      $2
          3        ASSIGN                                                   !0, ~4
   16     4        INIT_FCALL                                               'modifieslocallyclonedfoo'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0          
   17     7        INIT_FCALL                                               'var_dump'
          8        FETCH_DIM_R                                      ~7      !0, 0
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                                 
   20    11        FETCH_DIM_W                                      $9      !0, 0
         12        ASSIGN_REF                                               !1, $9
   22    13        INIT_FCALL                                               'modifieslocallyclonedfoo'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0          
   23    16        INIT_FCALL                                               'var_dump'
         17        FETCH_DIM_R                                      ~12     !0, 0
         18        SEND_VAL                                                 ~12
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function modifieslocallyclonedfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/G1VRc
function name:  modifiesLocallyClonedFoo
number of ops:  9
compiled vars:  !0 = $fooArr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        FETCH_DIM_R                                      ~2      !0, 0
          2        CLONE                                            ~3      ~2
          3        ASSIGN_DIM                                               !0, 0
          4        OP_DATA                                                  ~3
   13     5        FETCH_DIM_W                                      $4      !0, 0
          6        ASSIGN_OBJ                                               $4, 'bar'
          7        OP_DATA                                                  'bar'
   14     8      > RETURN                                                   null

End of function modifieslocallyclonedfoo

Class Foo: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.77 ms | 1008 KiB | 16 Q