3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public $elements = []; public function __clone() { // $elems = $this->elements; unset($this->elements); $this->elements = $elems; // this is a working fix before fixed in PHP directly } } $x = new A(); $test = &$x->elements; // this code outside class causes a different clone behaviour $y = clone $x; $y->elements['hello'] = 'world'; print_r($x); print_r($y);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q557K
function name:  (null)
number of ops:  17
compiled vars:  !0 = $x, !1 = $test, !2 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $3      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   13     3        FETCH_OBJ_W                                      $6      !0, 'elements'
          4        ASSIGN_REF                                               !1, $6
   14     5        CLONE                                            ~8      !0
          6        ASSIGN                                                   !2, ~8
   15     7        FETCH_OBJ_W                                      $10     !2, 'elements'
          8        ASSIGN_DIM                                               $10, 'hello'
          9        OP_DATA                                                  'world'
   17    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
   18    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Class A:
Function __clone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q557K
function name:  __clone
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E > > RETURN                                                   null

End of function __clone

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.86 ms | 1010 KiB | 14 Q