3v4l.org

run code in 300+ PHP versions simultaneously
--TEST-- Keeping a reference to an object property in an array should not override existing references ?> --FILE-- <?php class Container { /** @var \stdClass|null */ public $referencedProperty; public function __clone() { $this->referencedProperty = clone $this->referencedProperty; } } $references = []; $container = new Container(); $loadFieldByReference = function (& $referencedProperty) use (& $references) { $referencedProperty = new \stdClass(); $references[] = & $referencedProperty; }; $loadFieldByReference($container->referencedProperty); $container->referencedProperty->publicProperty = 123; $clone = clone $container; $clone->referencedProperty->publicProperty = 234; echo $container->referencedProperty->publicProperty, "\n"; echo $clone->referencedProperty->publicProperty, "\n"; echo $container->referencedProperty === $clone->referencedProperty ? "same\n" : "not same\n"; ?> --EXPECT-- 123 234 not same
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BNDsu
function name:  (null)
number of ops:  39
compiled vars:  !0 = $references, !1 = $container, !2 = $loadFieldByReference, !3 = $clone
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ECHO                                                     '--TEST--%0AKeeping+a+reference+to+an+object+property+in+an+array+should+not+override+existing+references%0A%3F%3E%0A--FILE--%0A'
   18     1        ASSIGN                                                   !0, <array>
   20     2        NEW                                              $5      'Container'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $5
   22     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FBNDsu%3A22%240'
          6        BIND_LEXICAL                                             ~8, !0
          7        ASSIGN                                                   !2, ~8
   27     8        INIT_DYNAMIC_CALL                                        !2
          9        CHECK_FUNC_ARG                                           
         10        FETCH_OBJ_FUNC_ARG                               $10     !1, 'referencedProperty'
         11        SEND_FUNC_ARG                                            $10
         12        DO_FCALL                                      0          
   29    13        FETCH_OBJ_W                                      $12     !1, 'referencedProperty'
         14        ASSIGN_OBJ                                               $12, 'publicProperty'
         15        OP_DATA                                                  123
   30    16        CLONE                                            ~14     !1
         17        ASSIGN                                                   !3, ~14
   31    18        FETCH_OBJ_W                                      $16     !3, 'referencedProperty'
         19        ASSIGN_OBJ                                               $16, 'publicProperty'
         20        OP_DATA                                                  234
   33    21        FETCH_OBJ_R                                      ~18     !1, 'referencedProperty'
         22        FETCH_OBJ_R                                      ~19     ~18, 'publicProperty'
         23        ECHO                                                     ~19
         24        ECHO                                                     '%0A'
   34    25        FETCH_OBJ_R                                      ~20     !3, 'referencedProperty'
         26        FETCH_OBJ_R                                      ~21     ~20, 'publicProperty'
         27        ECHO                                                     ~21
         28        ECHO                                                     '%0A'
   35    29        FETCH_OBJ_R                                      ~22     !1, 'referencedProperty'
         30        FETCH_OBJ_R                                      ~23     !3, 'referencedProperty'
         31        IS_IDENTICAL                                             ~22, ~23
         32      > JMPZ                                                     ~24, ->35
         33    >   QM_ASSIGN                                        ~25     'same%0A'
         34      > JMP                                                      ->36
         35    >   QM_ASSIGN                                        ~25     'not+same%0A'
         36    >   ECHO                                                     ~25
   38    37        ECHO                                                     '--EXPECT--%0A123%0A234%0Anot+same'
   41    38      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FBNDsu%3A22%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BNDsu
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $referencedProperty, !1 = $references
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   23     2        NEW                                              $2      'stdClass'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   24     5        FETCH_DIM_W                                      $5      !1
          6        ASSIGN_REF                                               $5, !0
   25     7      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FBNDsu%3A22%240

Class Container:
Function __clone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BNDsu
function name:  __clone
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~1      'referencedProperty'
          1        CLONE                                            ~2      ~1
          2        ASSIGN_OBJ                                               'referencedProperty'
          3        OP_DATA                                                  ~2
   15     4      > RETURN                                                   null

End of function __clone

End of class Container.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.96 ms | 1399 KiB | 13 Q