3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $childs = []; public function __serialize() { return [$this->childs]; } public function __unserialize(array $data) { list($this->childs) = $data; } } function createTree ($width, $depth) { $root = new Node(); $nextLevel = [$root]; for ($level=1; $level<$depth; $level++) { $levelRoots = $nextLevel; $nextLevel = []; while (count($levelRoots) > 0) { $levelRoot = array_shift($levelRoots); for ($w = 0; $w < $width; $w++) { $tester = new Node(); $levelRoot->childs[] = $tester; $nextLevel[] = $tester; } } } return $root; } $width = 3; ob_implicit_flush(); foreach (range(1, 10) as $depth) { $tree = createTree($width, $depth); echo "Testcase tree $width x $depth".PHP_EOL; echo "> Serializing now".PHP_EOL; $serialized = serialize($tree); echo "> Unserializing now".PHP_EOL; $tree = unserialize($serialized); // Lets test whether all is ok! $expectedSize = ($width**$depth - 1)/($width-1); $nodes = [$tree]; $count = 0; while (count($nodes) > 0) { $count++; $node = array_shift($nodes); foreach ($node->childs as $node) { $nodes[] = $node; } } echo "> Unserialized total node count was $count, expected $expectedSize: ".($expectedSize === $count ? 'CORRECT!' : 'INCORRECT'); echo PHP_EOL; echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 69
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 69
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 39
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
2 jumps found. (Code = 78) Position 1 = 47, Position 2 = 50
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 39
Branch analysis from position: 54
Branch analysis from position: 39
Branch analysis from position: 50
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
filename:       /in/C9dJE
function name:  (null)
number of ops:  71
compiled vars:  !0 = $width, !1 = $depth, !2 = $tree, !3 = $serialized, !4 = $expectedSize, !5 = $nodes, !6 = $count, !7 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, 3
   45     1        INIT_FCALL                                               'ob_implicit_flush'
          2        DO_ICALL                                                 
   47     3        INIT_FCALL                                               'range'
          4        SEND_VAL                                                 1
          5        SEND_VAL                                                 10
          6        DO_ICALL                                         $10     
          7      > FE_RESET_R                                       $11     $10, ->69
          8    > > FE_FETCH_R                                               $11, !1, ->69
   48     9    >   INIT_FCALL                                               'createtree'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $12     
         13        ASSIGN                                                   !2, $12
   50    14        ROPE_INIT                                     4  ~15     'Testcase+tree+'
         15        ROPE_ADD                                      1  ~15     ~15, !0
         16        ROPE_ADD                                      2  ~15     ~15, '+x+'
         17        ROPE_END                                      3  ~14     ~15, !1
         18        CONCAT                                           ~17     ~14, '%0A'
         19        ECHO                                                     ~17
   52    20        ECHO                                                     '%3E+Serializing+now%0A'
   53    21        INIT_FCALL                                               'serialize'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $18     
         24        ASSIGN                                                   !3, $18
   55    25        ECHO                                                     '%3E+Unserializing+now%0A'
   56    26        INIT_FCALL                                               'unserialize'
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                         $20     
         29        ASSIGN                                                   !2, $20
   59    30        POW                                              ~22     !0, !1
         31        SUB                                              ~23     ~22, 1
         32        SUB                                              ~24     !0, 1
         33        DIV                                              ~25     ~23, ~24
         34        ASSIGN                                                   !4, ~25
   61    35        INIT_ARRAY                                       ~27     !2
         36        ASSIGN                                                   !5, ~27
   62    37        ASSIGN                                                   !6, 0
   64    38      > JMP                                                      ->51
   65    39    >   PRE_INC                                                  !6
   67    40        INIT_FCALL                                               'array_shift'
         41        SEND_REF                                                 !5
         42        DO_ICALL                                         $31     
         43        ASSIGN                                                   !7, $31
   68    44        FETCH_OBJ_R                                      ~33     !7, 'childs'
         45      > FE_RESET_R                                       $34     ~33, ->50
         46    > > FE_FETCH_R                                               $34, !7, ->50
   69    47    >   ASSIGN_DIM                                               !5
         48        OP_DATA                                                  !7
   68    49      > JMP                                                      ->46
         50    >   FE_FREE                                                  $34
   64    51    >   COUNT                                            ~36     !5
         52        IS_SMALLER                                               0, ~36
         53      > JMPNZ                                                    ~37, ->39
   73    54    >   ROPE_INIT                                     5  ~39     '%3E+Unserialized+total+node+count+was+'
         55        ROPE_ADD                                      1  ~39     ~39, !6
         56        ROPE_ADD                                      2  ~39     ~39, '%2C+expected+'
         57        ROPE_ADD                                      3  ~39     ~39, !4
         58        ROPE_END                                      4  ~38     ~39, '%3A+'
         59        IS_IDENTICAL                                             !4, !6
         60      > JMPZ                                                     ~42, ->63
         61    >   QM_ASSIGN                                        ~43     'CORRECT%21'
         62      > JMP                                                      ->64
         63    >   QM_ASSIGN                                        ~43     'INCORRECT'
         64    >   CONCAT                                           ~44     ~38, ~43
         65        ECHO                                                     ~44
   75    66        ECHO                                                     '%0A'
   76    67        ECHO                                                     '%0A'
   47    68      > JMP                                                      ->8
         69    >   FE_FREE                                                  $11
   77    70      > RETURN                                                   1

Function createtree:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 9
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 12
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 9
Branch analysis from position: 35
Branch analysis from position: 9
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 18
Branch analysis from position: 29
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 18
Branch analysis from position: 29
Branch analysis from position: 18
filename:       /in/C9dJE
function name:  createTree
number of ops:  37
compiled vars:  !0 = $width, !1 = $depth, !2 = $root, !3 = $nextLevel, !4 = $level, !5 = $levelRoots, !6 = $levelRoot, !7 = $w, !8 = $tester
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        NEW                                              $9      'Node'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !2, $9
   21     5        INIT_ARRAY                                       ~12     !2
          6        ASSIGN                                                   !3, ~12
   23     7        ASSIGN                                                   !4, 1
          8      > JMP                                                      ->33
   24     9    >   ASSIGN                                                   !5, !3
   25    10        ASSIGN                                                   !3, <array>
   27    11      > JMP                                                      ->29
   28    12    >   INIT_FCALL                                               'array_shift'
         13        SEND_REF                                                 !5
         14        DO_ICALL                                         $17     
         15        ASSIGN                                                   !6, $17
   30    16        ASSIGN                                                   !7, 0
         17      > JMP                                                      ->27
   31    18    >   NEW                                              $20     'Node'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !8, $20
   33    21        FETCH_OBJ_W                                      $23     !6, 'childs'
         22        ASSIGN_DIM                                               $23
         23        OP_DATA                                                  !8
   35    24        ASSIGN_DIM                                               !3
         25        OP_DATA                                                  !8
   30    26        PRE_INC                                                  !7
         27    >   IS_SMALLER                                               !7, !0
         28      > JMPNZ                                                    ~27, ->18
   27    29    >   COUNT                                            ~28     !5
         30        IS_SMALLER                                               0, ~28
         31      > JMPNZ                                                    ~29, ->12
   23    32    >   PRE_INC                                                  !4
         33    >   IS_SMALLER                                               !4, !1
         34      > JMPNZ                                                    ~31, ->9
   40    35    > > RETURN                                                   !2
   41    36*     > RETURN                                                   null

End of function createtree

Class Node:
Function __serialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C9dJE
function name:  __serialize
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   FETCH_OBJ_R                                      ~0      'childs'
          1        INIT_ARRAY                                       ~1      ~0
          2      > RETURN                                                   ~1
   10     3*     > 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/C9dJE
function name:  __unserialize
number of ops:  7
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        QM_ASSIGN                                        ~1      !0
          2        FETCH_LIST_R                                     $2      ~1, 0
          3        ASSIGN_OBJ                                               'childs'
          4        OP_DATA                                                  $2
          5        FREE                                                     ~1
   15     6      > RETURN                                                   null

End of function __unserialize

End of class Node.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.51 ms | 1415 KiB | 24 Q