3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Reference { private static $DATA = []; private $index = 0; public function __construct($value) { // cannot create a reference of a reference if ($value instanceof self) { $this->index = $value->index; } else { $this->index = count(self::$DATA); self::$DATA[$this->index] = $value; } } public function get() { return self::$DATA[$this->index]; } public function set($value) { self::$DATA[$this->index] = $value; } } $orig = [1]; // $ref =& $orig[0]; $orig[0] = new Reference($orig[0]); $ref = clone $orig[0]; $copy = $orig; $copy[0] = clone $orig[0]; // creating a copy of what was in $orig[0] // $orig[0] = 10; $orig[0]->set(10); // var_dump($copy[0]); var_dump($copy[0]->get());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GS6sU
function name:  (null)
number of ops:  27
compiled vars:  !0 = $orig, !1 = $ref, !2 = $copy
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   31     1        NEW                                              $5      'Reference'
          2        CHECK_FUNC_ARG                                           
          3        FETCH_DIM_FUNC_ARG                               $6      !0, 0
          4        SEND_FUNC_ARG                                            $6
          5        DO_FCALL                                      0          
          6        ASSIGN_DIM                                               !0, 0
          7        OP_DATA                                                  $5
   32     8        FETCH_DIM_R                                      ~8      !0, 0
          9        CLONE                                            ~9      ~8
         10        ASSIGN                                                   !1, ~9
   34    11        ASSIGN                                                   !2, !0
   35    12        FETCH_DIM_R                                      ~13     !0, 0
         13        CLONE                                            ~14     ~13
         14        ASSIGN_DIM                                               !2, 0
         15        OP_DATA                                                  ~14
   38    16        FETCH_DIM_R                                      ~15     !0, 0
         17        INIT_METHOD_CALL                                         ~15, 'set'
         18        SEND_VAL_EX                                              10
         19        DO_FCALL                                      0          
   41    20        INIT_FCALL                                               'var_dump'
         21        FETCH_DIM_R                                      ~17     !2, 0
         22        INIT_METHOD_CALL                                         ~17, 'get'
         23        DO_FCALL                                      0  $18     
         24        SEND_VAR                                                 $18
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

Class Reference:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GS6sU
function name:  __construct
number of ops:  16
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        INSTANCEOF                                               !0
          2      > JMPZ                                                     ~1, ->7
   11     3    >   FETCH_OBJ_R                                      ~3      !0, 'index'
          4        ASSIGN_OBJ                                               'index'
          5        OP_DATA                                                  ~3
   10     6      > JMP                                                      ->15
   13     7    >   FETCH_STATIC_PROP_R          unknown             ~5      'DATA'
          8        COUNT                                            ~6      ~5
          9        ASSIGN_OBJ                                               'index'
         10        OP_DATA                                                  ~6
   14    11        FETCH_OBJ_R                                      ~8      'index'
         12        FETCH_STATIC_PROP_W          unknown             $7      'DATA'
         13        ASSIGN_DIM                                               $7, ~8
         14        OP_DATA                                                  !0
   16    15    > > RETURN                                                   null

End of function __construct

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GS6sU
function name:  get
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   FETCH_OBJ_R                                      ~1      'index'
          1        FETCH_STATIC_PROP_R          unknown             ~0      'DATA'
          2        FETCH_DIM_R                                      ~2      ~0, ~1
          3      > RETURN                                                   ~2
   20     4*     > RETURN                                                   null

End of function get

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GS6sU
function name:  set
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        FETCH_OBJ_R                                      ~2      'index'
          2        FETCH_STATIC_PROP_W          global              $1      'DATA'
          3        ASSIGN_DIM                                               $1, ~2
          4        OP_DATA                                                  !0
   24     5      > RETURN                                                   null

End of function set

End of class Reference.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.69 ms | 1003 KiB | 14 Q