3v4l.org

run code in 500+ PHP versions simultaneously
<?php // 'Child' object. class Child { public $property = 'foo'; } // 'Parent' object. class ParentA implements Serializable { public $rofl = 'foo'; public function serialize() { return serialize([$this->rofl]); } public function unserialize($data) { list($this->rofl) = unserialize($data); } } class ParentB extends ParentA { public $collection; public function __construct(array $items) { $this->collection = []; foreach ($items as $item) { $this->collection[] = $item; } } public function serialize() { return serialize([ 'foo' => $this->collection, 'parent' => parent::serialize() ]); } public function unserialize($data) { $data = unserialize($data); $this->collection = $data['foo']; parent::unserialize($data['parent']); } } // Wrapper object. class Wrapper { public $parent; public $children; public function __construct(ParentB $parent, array $children) { $this->parent = $parent; $this->children = []; foreach ($children as $child) { $this->children[] = $child; } } } $children = [new Child(), new Child(), new Child()]; $parent = new ParentB($children); $wrapper = new Wrapper($parent, $children); $data = serialize($wrapper); var_dump(unserialize($data));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WPdtA
function name:  (null)
number of ops:  32
compiled vars:  !0 = $children, !1 = $parent, !2 = $wrapper, !3 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                                'parenta'
   25     1        DECLARE_CLASS                                                'parentb', 'parenta'
   72     2        NEW                                                  $4      'Child'
          3        DO_FCALL                                          0          
          4        INIT_ARRAY                                           ~6      $4
          5        NEW                                                  $7      'Child'
          6        DO_FCALL                                          0          
          7        ADD_ARRAY_ELEMENT                                    ~6      $7
          8        NEW                                                  $9      'Child'
          9        DO_FCALL                                          0          
         10        ADD_ARRAY_ELEMENT                                    ~6      $9
         11        ASSIGN                                                       !0, ~6
   73    12        NEW                                                  $12     'ParentB'
         13        SEND_VAR_EX                                                  !0
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !1, $12
   74    16        NEW                                                  $15     'Wrapper'
         17        SEND_VAR_EX                                                  !1
         18        SEND_VAR_EX                                                  !0
         19        DO_FCALL                                          0          
         20        ASSIGN                                                       !2, $15
   76    21        INIT_FCALL                                                   'serialize'
         22        SEND_VAR                                                     !2
         23        DO_ICALL                                             $18     
         24        ASSIGN                                                       !3, $18
   77    25        INIT_FCALL                                                   'var_dump'
         26        INIT_FCALL                                                   'unserialize'
         27        SEND_VAR                                                     !3
         28        DO_ICALL                                             $20     
         29        SEND_VAR                                                     $20
         30        DO_ICALL                                                     
         31      > RETURN                                                       1

Class Child: [no user functions]
Class ParentA:
Function serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WPdtA
function name:  serialize
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                                   'serialize'
          1        FETCH_OBJ_R                                          ~0      'rofl'
          2        INIT_ARRAY                                           ~1      ~0
          3        SEND_VAL                                                     ~1
          4        DO_ICALL                                             $2      
          5      > RETURN                                                       $2
   17     6*     > RETURN                                                       null

End of function serialize

Function unserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WPdtA
function name:  unserialize
number of ops:  9
compiled vars:  !0 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
   21     1        INIT_FCALL                                                   'unserialize'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $1      
          4        FETCH_LIST_R                                         $2      $1, 0
          5        ASSIGN_OBJ                                                   'rofl'
          6        OP_DATA                                                      $2
          7        FREE                                                         $1
   22     8      > RETURN                                                       null

End of function unserialize

End of class ParentA.

Class ParentB:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/WPdtA
function name:  __construct
number of ops:  11
compiled vars:  !0 = $items, !1 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
   31     1        ASSIGN_OBJ                                                   'collection'
          2        OP_DATA                                                      <array>
   32     3      > FE_RESET_R                                           $3      !0, ->9
          4    > > FE_FETCH_R                                                   $3, !1, ->9
   34     5    >   FETCH_OBJ_W                                          $4      'collection'
          6        ASSIGN_DIM                                                   $4
          7        OP_DATA                                                      !1
   32     8      > JMP                                                          ->4
          9    >   FE_FREE                                                      $3
   36    10      > RETURN                                                       null

End of function __construct

Function serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WPdtA
function name:  serialize
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   INIT_FCALL                                                   'serialize'
   41     1        FETCH_OBJ_R                                          ~0      'collection'
          2        INIT_ARRAY                                           ~1      ~0, 'foo'
   42     3        INIT_STATIC_METHOD_CALL                                      'serialize'
          4        DO_FCALL                                          0  $2      
          5        ADD_ARRAY_ELEMENT                                    ~1      $2, 'parent'
          6        SEND_VAL                                                     ~1
   40     7        DO_ICALL                                             $3      
   42     8      > RETURN                                                       $3
   44     9*     > RETURN                                                       null

End of function serialize

Function unserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WPdtA
function name:  unserialize
number of ops:  14
compiled vars:  !0 = $data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   46     0  E >   RECV                                                 !0      
   48     1        INIT_FCALL                                                   'unserialize'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $1      
          4        ASSIGN                                                       !0, $1
   49     5        FETCH_DIM_R                                          ~4      !0, 'foo'
          6        ASSIGN_OBJ                                                   'collection'
          7        OP_DATA                                                      ~4
   50     8        INIT_STATIC_METHOD_CALL                                      'unserialize'
          9        CHECK_FUNC_ARG                                               
         10        FETCH_DIM_FUNC_ARG                                   $5      !0, 'parent'
         11        SEND_FUNC_ARG                                                $5
         12        DO_FCALL                                          0          
   51    13      > RETURN                                                       null

End of function unserialize

End of class ParentB.

Class Wrapper:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/WPdtA
function name:  __construct
number of ops:  14
compiled vars:  !0 = $parent, !1 = $children, !2 = $child
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   60     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   62     2        ASSIGN_OBJ                                                   'parent'
          3        OP_DATA                                                      !0
   64     4        ASSIGN_OBJ                                                   'children'
          5        OP_DATA                                                      <array>
   65     6      > FE_RESET_R                                           $5      !1, ->12
          7    > > FE_FETCH_R                                                   $5, !2, ->12
   67     8    >   FETCH_OBJ_W                                          $6      'children'
          9        ASSIGN_DIM                                                   $6
         10        OP_DATA                                                      !2
   65    11      > JMP                                                          ->7
         12    >   FE_FREE                                                      $5
   69    13      > RETURN                                                       null

End of function __construct

End of class Wrapper.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.65 ms | 3308 KiB | 16 Q