3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Widget implements Serializable { public $references = array(); public $config; public function serialize() { $vars = get_object_vars($this); $vars['config'] = serialize($vars['config']); $serialized = serialize($vars); return $serialized; } public function unserialize($serialized) { $array = unserialize($serialized); $array['config'] = unserialize($array['config']); foreach($array as $k => $v) { $this->$k = $v; } } } class Placeholder { public $id; public function __construct($id) { $this->id = $id; } } $collection = array(); $placeholder1 = new Placeholder(1); $placeholder2 = new Placeholder(2); $widget1 = new Widget; $widget1->config = array('id_section' => 9); $widget1->references[] = $placeholder1; $widget2 = new Widget; $widget2->config = array('id_section' => 9); $widget2->references[] = $placeholder2; $widget3 = new Widget; $widget3->config = array('id_section' => 9); $widget3->references[] = $placeholder1; $widget4 = new Widget; $widget4->config = array('id_section' => 9); $widget4->references[] = $placeholder1; $collection[] = $widget1; $collection[] = $widget2; $collection[] = $widget3; // reference to placeholder will be missing here $collection[] = $widget4; // reference to placeholder will be missing here print_r(unserialize(serialize($collection)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjJmf
function name:  (null)
number of ops:  60
compiled vars:  !0 = $collection, !1 = $placeholder1, !2 = $placeholder2, !3 = $widget1, !4 = $widget2, !5 = $widget3, !6 = $widget4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'widget'
   42     1        ASSIGN                                                   !0, <array>
   44     2        NEW                                              $8      'Placeholder'
          3        SEND_VAL_EX                                              1
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $8
   45     6        NEW                                              $11     'Placeholder'
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $11
   47    10        NEW                                              $14     'Widget'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $14
   48    13        ASSIGN_OBJ                                               !3, 'config'
         14        OP_DATA                                                  <array>
   49    15        FETCH_OBJ_W                                      $18     !3, 'references'
         16        ASSIGN_DIM                                               $18
         17        OP_DATA                                                  !1
   51    18        NEW                                              $20     'Widget'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !4, $20
   52    21        ASSIGN_OBJ                                               !4, 'config'
         22        OP_DATA                                                  <array>
   53    23        FETCH_OBJ_W                                      $24     !4, 'references'
         24        ASSIGN_DIM                                               $24
         25        OP_DATA                                                  !2
   55    26        NEW                                              $26     'Widget'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !5, $26
   56    29        ASSIGN_OBJ                                               !5, 'config'
         30        OP_DATA                                                  <array>
   57    31        FETCH_OBJ_W                                      $30     !5, 'references'
         32        ASSIGN_DIM                                               $30
         33        OP_DATA                                                  !1
   59    34        NEW                                              $32     'Widget'
         35        DO_FCALL                                      0          
         36        ASSIGN                                                   !6, $32
   60    37        ASSIGN_OBJ                                               !6, 'config'
         38        OP_DATA                                                  <array>
   61    39        FETCH_OBJ_W                                      $36     !6, 'references'
         40        ASSIGN_DIM                                               $36
         41        OP_DATA                                                  !1
   63    42        ASSIGN_DIM                                               !0
         43        OP_DATA                                                  !3
   64    44        ASSIGN_DIM                                               !0
         45        OP_DATA                                                  !4
   65    46        ASSIGN_DIM                                               !0
         47        OP_DATA                                                  !5
   66    48        ASSIGN_DIM                                               !0
         49        OP_DATA                                                  !6
   68    50        INIT_FCALL                                               'print_r'
         51        INIT_FCALL                                               'unserialize'
         52        INIT_FCALL                                               'serialize'
         53        SEND_VAR                                                 !0
         54        DO_ICALL                                         $42     
         55        SEND_VAR                                                 $42
         56        DO_ICALL                                         $43     
         57        SEND_VAR                                                 $43
         58        DO_ICALL                                                 
         59      > RETURN                                                   1

Class Widget:
Function serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjJmf
function name:  serialize
number of ops:  17
compiled vars:  !0 = $vars, !1 = $serialized
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'get_object_vars'
          1        FETCH_THIS                                       ~2      
          2        SEND_VAL                                                 ~2
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
   12     5        INIT_FCALL                                               'serialize'
          6        FETCH_DIM_R                                      ~6      !0, 'config'
          7        SEND_VAL                                                 ~6
          8        DO_ICALL                                         $7      
          9        ASSIGN_DIM                                               !0, 'config'
         10        OP_DATA                                                  $7
   14    11        INIT_FCALL                                               'serialize'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !1, $8
   16    15      > RETURN                                                   !1
   17    16*     > RETURN                                                   null

End of function serialize

Function unserialize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/FjJmf
function name:  unserialize
number of ops:  19
compiled vars:  !0 = $serialized, !1 = $array, !2 = $v, !3 = $k
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                                         $4      
          4        ASSIGN                                                   !1, $4
   23     5        INIT_FCALL                                               'unserialize'
          6        FETCH_DIM_R                                      ~7      !1, 'config'
          7        SEND_VAL                                                 ~7
          8        DO_ICALL                                         $8      
          9        ASSIGN_DIM                                               !1, 'config'
         10        OP_DATA                                                  $8
   25    11      > FE_RESET_R                                       $9      !1, ->17
         12    > > FE_FETCH_R                                       ~10     $9, !2, ->17
         13    >   ASSIGN                                                   !3, ~10
   27    14        ASSIGN_OBJ                                               !3
         15        OP_DATA                                                  !2
   25    16      > JMP                                                      ->12
         17    >   FE_FREE                                                  $9
   29    18      > RETURN                                                   null

End of function unserialize

End of class Widget.

Class Placeholder:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FjJmf
function name:  __construct
number of ops:  4
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        ASSIGN_OBJ                                               'id'
          2        OP_DATA                                                  !0
   39     3      > RETURN                                                   null

End of function __construct

End of class Placeholder.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.62 ms | 1404 KiB | 21 Q