3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Item { public ?array $children = []; public ?Item $parent = null; public function addChild(Item $item): Item { $item->setParent($this); $this->children[] = $item; return $this; } public function setParent(Item $parent): void { $this->parent = $parent; } public function __sleep() { return array_keys(get_object_vars($this)); } } class Tree { public array $items = []; public function addItem(Item $item): self { $this->items[] = $item; return $this; } public function __clone() { foreach ($this->items as $key => $item) { $clone = clone $item; $this->items[$key] = $clone; } } } class Forest { public Tree $first; public Tree $second; public function __construct(Tree $first, Tree $second) { $this->first = $first; $this->second = $second; } } $charge = new Item(); $baseProduct = new Item(); $base = new Tree(); $base->addItem($baseProduct); $baseProduct->addCHild($charge); $second = clone $base; $data = new Forest($second, $base); assert(is_array($data->second->items[0]->children)); $data = unserialize(serialize($data)); assert(is_array($data->second->items[0]->children)); echo 'OK';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2m3Jb
function name:  (null)
number of ops:  51
compiled vars:  !0 = $charge, !1 = $baseProduct, !2 = $base, !3 = $second, !4 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   61     0  E >   NEW                                                  $5      'Item'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $5
   63     3        NEW                                                  $8      'Item'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !1, $8
   64     6        NEW                                                  $11     'Tree'
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !2, $11
   65     9        INIT_METHOD_CALL                                             !2, 'addItem'
         10        SEND_VAR_EX                                                  !1
         11        DO_FCALL                                          0          
   66    12        INIT_METHOD_CALL                                             !1, 'addCHild'
         13        SEND_VAR_EX                                                  !0
         14        DO_FCALL                                          0          
   68    15        CLONE                                                ~16     !2
         16        ASSIGN                                                       !3, ~16
   70    17        NEW                                                  $18     'Forest'
         18        SEND_VAR_EX                                                  !3
         19        SEND_VAR_EX                                                  !2
         20        DO_FCALL                                          0          
         21        ASSIGN                                                       !4, $18
   72    22        ASSERT_CHECK                                                 
         23        INIT_FCALL                                                   'assert'
         24        FETCH_OBJ_R                                          ~21     !4, 'second'
         25        FETCH_OBJ_R                                          ~22     ~21, 'items'
         26        FETCH_DIM_R                                          ~23     ~22, 0
         27        FETCH_OBJ_R                                          ~24     ~23, 'children'
         28        TYPE_CHECK                                      128  ~25     ~24
         29        SEND_VAL                                                     ~25
         30        SEND_VAL                                                     'assert%28is_array%28%24data-%3Esecond-%3Eitems%5B0%5D-%3Echildren%29%29'
         31        DO_ICALL                                                     
   74    32        INIT_FCALL                                                   'unserialize'
         33        INIT_FCALL                                                   'serialize'
         34        SEND_VAR                                                     !4
         35        DO_ICALL                                             $27     
         36        SEND_VAR                                                     $27
         37        DO_ICALL                                             $28     
         38        ASSIGN                                                       !4, $28
   76    39        ASSERT_CHECK                                                 
         40        INIT_FCALL                                                   'assert'
         41        FETCH_OBJ_R                                          ~30     !4, 'second'
         42        FETCH_OBJ_R                                          ~31     ~30, 'items'
         43        FETCH_DIM_R                                          ~32     ~31, 0
         44        FETCH_OBJ_R                                          ~33     ~32, 'children'
         45        TYPE_CHECK                                      128  ~34     ~33
         46        SEND_VAL                                                     ~34
         47        SEND_VAL                                                     'assert%28is_array%28%24data-%3Esecond-%3Eitems%5B0%5D-%3Echildren%29%29'
         48        DO_ICALL                                                     
   78    49        ECHO                                                         'OK'
         50      > RETURN                                                       1

Class Item:
Function addchild:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2m3Jb
function name:  addChild
number of ops:  13
compiled vars:  !0 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   11     1        INIT_METHOD_CALL                                             !0, 'setParent'
          2        FETCH_THIS                                           $1      
          3        SEND_VAR_EX                                                  $1
          4        DO_FCALL                                          0          
   12     5        FETCH_OBJ_W                                          $3      'children'
          6        ASSIGN_DIM                                                   $3
          7        OP_DATA                                                      !0
   14     8        FETCH_THIS                                           ~5      
          9        VERIFY_RETURN_TYPE                                           ~5
         10      > RETURN                                                       ~5
   15    11*       VERIFY_RETURN_TYPE                                           
         12*     > RETURN                                                       null

End of function addchild

Function setparent:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2m3Jb
function name:  setParent
number of ops:  4
compiled vars:  !0 = $parent
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
   19     1        ASSIGN_OBJ                                                   'parent'
          2        OP_DATA                                                      !0
   20     3      > RETURN                                                       null

End of function setparent

Function __sleep:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2m3Jb
function name:  __sleep
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                                   'array_keys'
          1        INIT_FCALL                                                   'get_object_vars'
          2        FETCH_THIS                                           ~0      
          3        SEND_VAL                                                     ~0
          4        DO_ICALL                                             $1      
          5        SEND_VAR                                                     $1
          6        DO_ICALL                                             $2      
          7      > RETURN                                                       $2
   25     8*     > RETURN                                                       null

End of function __sleep

End of class Item.

Class Tree:
Function additem:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2m3Jb
function name:  addItem
number of ops:  9
compiled vars:  !0 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   RECV                                                 !0      
   34     1        FETCH_OBJ_W                                          $1      'items'
          2        ASSIGN_DIM                                                   $1
          3        OP_DATA                                                      !0
   36     4        FETCH_THIS                                           ~3      
          5        VERIFY_RETURN_TYPE                                           ~3
          6      > RETURN                                                       ~3
   37     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function additem

Function __clone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/2m3Jb
function name:  __clone
number of ops:  12
compiled vars:  !0 = $item, !1 = $key, !2 = $clone
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   FETCH_OBJ_R                                          ~3      'items'
          1      > FE_RESET_R                                           $4      ~3, ->10
          2    > > FE_FETCH_R                                           ~5      $4, !0, ->10
          3    >   ASSIGN                                                       !1, ~5
   42     4        CLONE                                                ~7      !0
          5        ASSIGN                                                       !2, ~7
   43     6        FETCH_OBJ_W                                          $9      'items'
          7        ASSIGN_DIM                                                   $9, !1
          8        OP_DATA                                                      !2
   41     9      > JMP                                                          ->2
         10    >   FE_FREE                                                      $4
   45    11      > RETURN                                                       null

End of function __clone

End of class Tree.

Class Forest:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2m3Jb
function name:  __construct
number of ops:  7
compiled vars:  !0 = $first, !1 = $second
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   53     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   55     2        ASSIGN_OBJ                                                   'first'
          3        OP_DATA                                                      !0
   56     4        ASSIGN_OBJ                                                   'second'
          5        OP_DATA                                                      !1
   57     6      > RETURN                                                       null

End of function __construct

End of class Forest.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.19 ms | 496 KiB | 12 Q