3v4l.org

run code in 500+ PHP versions simultaneously
<?php class MenuLinkTreeElement { public $link; public $subtree; public $depth; public $hasChildren; public $inActiveTrail; public $access; public $options; public function __construct($link, $has_children, $depth, $in_active_trail, array $subtree) { $this->link = $link; $this->hasChildren = $has_children; $this->depth = $depth; $this->subtree = $subtree; $this->inActiveTrail = $in_active_trail; $this->access = NULL; $this->options = array(); } public function count() { $sum = function ($carry, MenuLinkTreeElement $element) { return $carry + $element->count(); }; return 1 + array_reduce($this->subtree, $sum); } } // Arrays. $memory_before = memory_get_usage(); $array_start = microtime(TRUE); $storage = array(); for ($i = 0; $i < 1000; $i++) { $storage[] = array( 'link' => new StdClass(), 'has_children' => TRUE, 'depth' => 3, 'in_active_trail' => FALSE, 'below' => array(), 'access' => NULL, 'options' => array(), ); } $array_time = microtime(TRUE) - $array_start; $array_memory = memory_get_usage() - $memory_before; unset($storage); // Objects. $memory_before = memory_get_usage(); $object_start = microtime(TRUE); $storage = array(); for ($i = 0; $i < 1000; $i++) { $storage[] = new MenuLinkTreeElement(new StdClass(), TRUE, 3, FALSE, array()); } $object_time = microtime(TRUE) - $object_start; $object_memory = memory_get_usage() - $memory_before; unset($storage); echo 'arrays: ' . number_format($array_time, 3) . ' s, ' . ($array_memory/1024) . " KB\n"; echo 'objects: ' . number_format($object_time, 3) . ' s, ' . ($object_memory/1024) . " KB\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 10
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 44
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 44
Branch analysis from position: 58
Branch analysis from position: 44
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 10
Branch analysis from position: 24
Branch analysis from position: 10
filename:       /in/XcfvE
function name:  (null)
number of ops:  89
compiled vars:  !0 = $memory_before, !1 = $array_start, !2 = $storage, !3 = $i, !4 = $array_time, !5 = $array_memory, !6 = $object_start, !7 = $object_time, !8 = $object_memory
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                                   'memory_get_usage'
          1        DO_ICALL                                             $9      
          2        ASSIGN                                                       !0, $9
   35     3        INIT_FCALL                                                   'microtime'
          4        SEND_VAL                                                     <true>
          5        DO_ICALL                                             $11     
          6        ASSIGN                                                       !1, $11
   36     7        ASSIGN                                                       !2, <array>
   37     8        ASSIGN                                                       !3, 0
          9      > JMP                                                          ->22
   39    10    >   NEW                                                  $16     'StdClass'
         11        DO_FCALL                                          0          
         12        INIT_ARRAY                                           ~18     $16, 'link'
         13        ADD_ARRAY_ELEMENT                                    ~18     <true>, 'has_children'
   41    14        ADD_ARRAY_ELEMENT                                    ~18     3, 'depth'
   39    15        ADD_ARRAY_ELEMENT                                    ~18     <false>, 'in_active_trail'
         16        ADD_ARRAY_ELEMENT                                    ~18     <array>, 'below'
         17        ADD_ARRAY_ELEMENT                                    ~18     null, 'access'
         18        ADD_ARRAY_ELEMENT                                    ~18     <array>, 'options'
   38    19        ASSIGN_DIM                                                   !2
   39    20        OP_DATA                                                      ~18
   37    21        PRE_INC                                                      !3
         22    >   IS_SMALLER                                                   !3, 1000
         23      > JMPNZ                                                        ~20, ->10
   48    24    >   INIT_FCALL                                                   'microtime'
         25        SEND_VAL                                                     <true>
         26        DO_ICALL                                             $21     
         27        SUB                                                  ~22     $21, !1
         28        ASSIGN                                                       !4, ~22
   49    29        INIT_FCALL                                                   'memory_get_usage'
         30        DO_ICALL                                             $24     
         31        SUB                                                  ~25     $24, !0
         32        ASSIGN                                                       !5, ~25
   50    33        UNSET_CV                                                     !2
   54    34        INIT_FCALL                                                   'memory_get_usage'
         35        DO_ICALL                                             $27     
         36        ASSIGN                                                       !0, $27
   55    37        INIT_FCALL                                                   'microtime'
         38        SEND_VAL                                                     <true>
         39        DO_ICALL                                             $29     
         40        ASSIGN                                                       !6, $29
   56    41        ASSIGN                                                       !2, <array>
   57    42        ASSIGN                                                       !3, 0
         43      > JMP                                                          ->56
   58    44    >   NEW                                                  $34     'MenuLinkTreeElement'
         45        NEW                                                  $35     'StdClass'
         46        DO_FCALL                                          0          
         47        SEND_VAR_NO_REF_EX                                           $35
         48        SEND_VAL_EX                                                  <true>
         49        SEND_VAL_EX                                                  3
         50        SEND_VAL_EX                                                  <false>
         51        SEND_VAL_EX                                                  <array>
         52        DO_FCALL                                          0          
         53        ASSIGN_DIM                                                   !2
         54        OP_DATA                                                      $34
   57    55        PRE_INC                                                      !3
         56    >   IS_SMALLER                                                   !3, 1000
         57      > JMPNZ                                                        ~39, ->44
   60    58    >   INIT_FCALL                                                   'microtime'
         59        SEND_VAL                                                     <true>
         60        DO_ICALL                                             $40     
         61        SUB                                                  ~41     $40, !6
         62        ASSIGN                                                       !7, ~41
   61    63        INIT_FCALL                                                   'memory_get_usage'
         64        DO_ICALL                                             $43     
         65        SUB                                                  ~44     $43, !0
         66        ASSIGN                                                       !8, ~44
   62    67        UNSET_CV                                                     !2
   64    68        INIT_FCALL                                                   'number_format'
         69        SEND_VAR                                                     !4
         70        SEND_VAL                                                     3
         71        DO_ICALL                                             $46     
         72        CONCAT                                               ~47     'arrays%3A+', $46
         73        CONCAT                                               ~48     ~47, '+s%2C+'
         74        DIV                                                  ~49     !5, 1024
         75        CONCAT                                               ~50     ~48, ~49
         76        CONCAT                                               ~51     ~50, '+KB%0A'
         77        ECHO                                                         ~51
   65    78        INIT_FCALL                                                   'number_format'
         79        SEND_VAR                                                     !7
         80        SEND_VAL                                                     3
         81        DO_ICALL                                             $52     
         82        CONCAT                                               ~53     'objects%3A+', $52
         83        CONCAT                                               ~54     ~53, '+s%2C+'
         84        DIV                                                  ~55     !8, 1024
         85        CONCAT                                               ~56     ~54, ~55
         86        CONCAT                                               ~57     ~56, '+KB%0A'
         87        ECHO                                                         ~57
         88      > RETURN                                                       1

Class MenuLinkTreeElement:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XcfvE
function name:  __construct
number of ops:  20
compiled vars:  !0 = $link, !1 = $has_children, !2 = $depth, !3 = $in_active_trail, !4 = $subtree
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV                                                 !3      
          4        RECV                                                 !4      
   14     5        ASSIGN_OBJ                                                   'link'
          6        OP_DATA                                                      !0
   15     7        ASSIGN_OBJ                                                   'hasChildren'
          8        OP_DATA                                                      !1
   16     9        ASSIGN_OBJ                                                   'depth'
         10        OP_DATA                                                      !2
   17    11        ASSIGN_OBJ                                                   'subtree'
         12        OP_DATA                                                      !4
   18    13        ASSIGN_OBJ                                                   'inActiveTrail'
         14        OP_DATA                                                      !3
   19    15        ASSIGN_OBJ                                                   'access'
         16        OP_DATA                                                      null
   20    17        ASSIGN_OBJ                                                   'options'
         18        OP_DATA                                                      <array>
   21    19      > RETURN                                                       null

End of function __construct

Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XcfvE
function name:  count
number of ops:  10
compiled vars:  !0 = $sum
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   DECLARE_LAMBDA_FUNCTION                              ~1      [0]
          1        ASSIGN                                                       !0, ~1
   27     2        INIT_FCALL                                                   'array_reduce'
          3        FETCH_OBJ_R                                          ~3      'subtree'
          4        SEND_VAL                                                     ~3
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $4      
          7        ADD                                                  ~5      1, $4
          8      > RETURN                                                       ~5
   28     9*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XcfvE
function name:  {closure:MenuLinkTreeElement::count():24}
number of ops:  7
compiled vars:  !0 = $carry, !1 = $element
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   25     2        INIT_METHOD_CALL                                             !1, 'count'
          3        DO_FCALL                                          0  $2      
          4        ADD                                                  ~3      !0, $2
          5      > RETURN                                                       ~3
   26     6*     > RETURN                                                       null

End of Dynamic Function 0

End of function count

End of class MenuLinkTreeElement.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.29 ms | 1991 KiB | 17 Q