3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node implements Countable { private $nodes = []; public function __construct(array $nodes = []) { $this->nodes = $nodes; } public function getCount() { return count($this->nodes); } private function getCountRecursive() { $count = 0; foreach ($this->nodes as $node) { $count += ($node->getCountRecursive() + 1); } return $count; } public function count($mode = COUNT_NORMAL){ if ($mode === COUNT_RECURSIVE) { return $this->getCountRecursive(); } return $this->getCount(); } } $node = new Node([ new Node([ new Node([ new Node([ new Node(), new Node(), new Node(), ]), new Node(), new Node(), ]), new Node(), new Node(), ]), new Node(), ]); var_dump(count($node), count($node, COUNT_RECURSIVE));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Mc5k3
function name:  (null)
number of ops:  51
compiled vars:  !0 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'node'
   31     1        NEW                                              $1      'Node'
   32     2        NEW                                              $2      'Node'
   33     3        NEW                                              $3      'Node'
   34     4        NEW                                              $4      'Node'
   35     5        NEW                                              $5      'Node'
          6        DO_FCALL                                      0          
          7        INIT_ARRAY                                       ~7      $5
   36     8        NEW                                              $8      'Node'
          9        DO_FCALL                                      0          
         10        ADD_ARRAY_ELEMENT                                ~7      $8
   37    11        NEW                                              $10     'Node'
         12        DO_FCALL                                      0          
         13        ADD_ARRAY_ELEMENT                                ~7      $10
         14        SEND_VAL_EX                                              ~7
         15        DO_FCALL                                      0          
         16        INIT_ARRAY                                       ~13     $4
   39    17        NEW                                              $14     'Node'
         18        DO_FCALL                                      0          
         19        ADD_ARRAY_ELEMENT                                ~13     $14
   40    20        NEW                                              $16     'Node'
         21        DO_FCALL                                      0          
         22        ADD_ARRAY_ELEMENT                                ~13     $16
         23        SEND_VAL_EX                                              ~13
         24        DO_FCALL                                      0          
         25        INIT_ARRAY                                       ~19     $3
   42    26        NEW                                              $20     'Node'
         27        DO_FCALL                                      0          
         28        ADD_ARRAY_ELEMENT                                ~19     $20
   43    29        NEW                                              $22     'Node'
         30        DO_FCALL                                      0          
         31        ADD_ARRAY_ELEMENT                                ~19     $22
         32        SEND_VAL_EX                                              ~19
         33        DO_FCALL                                      0          
         34        INIT_ARRAY                                       ~25     $2
   45    35        NEW                                              $26     'Node'
         36        DO_FCALL                                      0          
         37        ADD_ARRAY_ELEMENT                                ~25     $26
         38        SEND_VAL_EX                                              ~25
         39        DO_FCALL                                      0          
   31    40        ASSIGN                                                   !0, $1
   48    41        INIT_FCALL                                               'var_dump'
         42        COUNT                                            ~30     !0
         43        SEND_VAL                                                 ~30
         44        INIT_FCALL                                               'count'
         45        SEND_VAR                                                 !0
         46        SEND_VAL                                                 1
         47        DO_ICALL                                         $31     
         48        SEND_VAR                                                 $31
         49        DO_ICALL                                                 
         50      > RETURN                                                   1

Class Node:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Mc5k3
function name:  __construct
number of ops:  4
compiled vars:  !0 = $nodes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV_INIT                                        !0      <array>
    8     1        ASSIGN_OBJ                                               'nodes'
          2        OP_DATA                                                  !0
    9     3      > RETURN                                                   null

End of function __construct

Function getcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Mc5k3
function name:  getCount
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~0      'nodes'
          1        COUNT                                            ~1      ~0
          2      > RETURN                                                   ~1
   13     3*     > RETURN                                                   null

End of function getcount

Function getcountrecursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/Mc5k3
function name:  getCountRecursive
number of ops:  12
compiled vars:  !0 = $count, !1 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, 0
   17     1        FETCH_OBJ_R                                      ~3      'nodes'
          2      > FE_RESET_R                                       $4      ~3, ->9
          3    > > FE_FETCH_R                                               $4, !1, ->9
   18     4    >   INIT_METHOD_CALL                                         !1, 'getCountRecursive'
          5        DO_FCALL                                      0  $5      
          6        ADD                                              ~6      $5, 1
          7        ASSIGN_OP                                     1          !0, ~6
   17     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $4
   20    10      > RETURN                                                   !0
   21    11*     > RETURN                                                   null

End of function getcountrecursive

Function count:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Mc5k3
function name:  count
number of ops:  10
compiled vars:  !0 = $mode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV_INIT                                        !0      <const ast>
   24     1        IS_IDENTICAL                                             !0, 1
          2      > JMPZ                                                     ~1, ->6
   25     3    >   INIT_METHOD_CALL                                         'getCountRecursive'
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   27     6    >   INIT_METHOD_CALL                                         'getCount'
          7        DO_FCALL                                      0  $3      
          8      > RETURN                                                   $3
   28     9*     > RETURN                                                   null

End of function count

End of class Node.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.32 ms | 1404 KiB | 17 Q