3v4l.org

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

Class Node:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gsSLC
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/gsSLC
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/gsSLC
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

End of class Node.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.41 ms | 1400 KiB | 15 Q