3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MenuElement { public $id; public $children = array(); public function __construct($id) { $this->id = $id; } public function addChild(MenuElement $menuElement) { array_push($this->children, $menuElement); } } $menuElement1 = new MenuElement(1); $menuElement11 = new MenuElement(11); $menuElement12 = new MenuElement(12); $menuElement121 = new MenuElement(121); $menuElement122 = new MenuElement(122); $menuElement123 = new MenuElement(123); $menuElement1211 = new MenuElement(1211); $menuElement121->addChild($menuElement1211); $menuElement12->addChild($menuElement121); $menuElement12->addChild($menuElement122); $menuElement12->addChild($menuElement123); $menuElement1->addChild($menuElement11); $menuElement1->addChild($menuElement12); function foo(MenuElement $elt, $level = 0) { if (0 == $level) echo '<ul>'.PHP_EOL; echo str_repeat(' ', $level+1).'<li>'.$elt->id; if (!count($elt->children)) { echo '</li>'.PHP_EOL; return; } echo PHP_EOL.str_repeat(' ', $level+2).'<ul>'.PHP_EOL; foreach($elt->children as $child) foo($child, $level+2); echo str_repeat(' ', $level+2).'</ul>'.PHP_EOL; echo str_repeat(' ', $level+1).'</li>'.PHP_EOL; if (0 == $level) echo '</ul>'.PHP_EOL; } foo($menuElement1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YFpZc
function name:  (null)
number of ops:  50
compiled vars:  !0 = $menuElement1, !1 = $menuElement11, !2 = $menuElement12, !3 = $menuElement121, !4 = $menuElement122, !5 = $menuElement123, !6 = $menuElement1211
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $7      'MenuElement'
          1        SEND_VAL_EX                                              1
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $7
   16     4        NEW                                              $10     'MenuElement'
          5        SEND_VAL_EX                                              11
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $10
   17     8        NEW                                              $13     'MenuElement'
          9        SEND_VAL_EX                                              12
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $13
   18    12        NEW                                              $16     'MenuElement'
         13        SEND_VAL_EX                                              121
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !3, $16
   19    16        NEW                                              $19     'MenuElement'
         17        SEND_VAL_EX                                              122
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !4, $19
   20    20        NEW                                              $22     'MenuElement'
         21        SEND_VAL_EX                                              123
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !5, $22
   21    24        NEW                                              $25     'MenuElement'
         25        SEND_VAL_EX                                              1211
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !6, $25
   22    28        INIT_METHOD_CALL                                         !3, 'addChild'
         29        SEND_VAR_EX                                              !6
         30        DO_FCALL                                      0          
   23    31        INIT_METHOD_CALL                                         !2, 'addChild'
         32        SEND_VAR_EX                                              !3
         33        DO_FCALL                                      0          
   24    34        INIT_METHOD_CALL                                         !2, 'addChild'
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0          
   25    37        INIT_METHOD_CALL                                         !2, 'addChild'
         38        SEND_VAR_EX                                              !5
         39        DO_FCALL                                      0          
   26    40        INIT_METHOD_CALL                                         !0, 'addChild'
         41        SEND_VAR_EX                                              !1
         42        DO_FCALL                                      0          
   27    43        INIT_METHOD_CALL                                         !0, 'addChild'
         44        SEND_VAR_EX                                              !2
         45        DO_FCALL                                      0          
   42    46        INIT_FCALL                                               'foo'
         47        SEND_VAR                                                 !0
         48        DO_FCALL                                      0          
         49      > RETURN                                                   1

Function foo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 38
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 58
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 38
Branch analysis from position: 5
filename:       /in/YFpZc
function name:  foo
number of ops:  59
compiled vars:  !0 = $elt, !1 = $level, !2 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   30     2        IS_EQUAL                                                 !1, 0
          3      > JMPZ                                                     ~3, ->5
          4    >   ECHO                                                     '%3Cul%3E%0A'
   31     5    >   INIT_FCALL                                               'str_repeat'
          6        SEND_VAL                                                 '++'
          7        ADD                                              ~4      !1, 1
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        CONCAT                                           ~6      $5, '%3Cli%3E'
         11        FETCH_OBJ_R                                      ~7      !0, 'id'
         12        CONCAT                                           ~8      ~6, ~7
         13        ECHO                                                     ~8
   32    14        FETCH_OBJ_R                                      ~9      !0, 'children'
         15        COUNT                                            ~10     ~9
         16        BOOL_NOT                                         ~11     ~10
         17      > JMPZ                                                     ~11, ->20
   33    18    >   ECHO                                                     '%3C%2Fli%3E%0A'
   34    19      > RETURN                                                   null
   36    20    >   INIT_FCALL                                               'str_repeat'
         21        SEND_VAL                                                 '++'
         22        ADD                                              ~12     !1, 2
         23        SEND_VAL                                                 ~12
         24        DO_ICALL                                         $13     
         25        CONCAT                                           ~14     '%0A', $13
         26        CONCAT                                           ~15     ~14, '%3Cul%3E'
         27        CONCAT                                           ~16     ~15, '%0A'
         28        ECHO                                                     ~16
   37    29        FETCH_OBJ_R                                      ~17     !0, 'children'
         30      > FE_RESET_R                                       $18     ~17, ->38
         31    > > FE_FETCH_R                                               $18, !2, ->38
         32    >   INIT_FCALL_BY_NAME                                       'foo'
         33        SEND_VAR_EX                                              !2
         34        ADD                                              ~19     !1, 2
         35        SEND_VAL_EX                                              ~19
         36        DO_FCALL                                      0          
         37      > JMP                                                      ->31
         38    >   FE_FREE                                                  $18
   38    39        INIT_FCALL                                               'str_repeat'
         40        SEND_VAL                                                 '++'
         41        ADD                                              ~21     !1, 2
         42        SEND_VAL                                                 ~21
         43        DO_ICALL                                         $22     
         44        CONCAT                                           ~23     $22, '%3C%2Ful%3E'
         45        CONCAT                                           ~24     ~23, '%0A'
         46        ECHO                                                     ~24
   39    47        INIT_FCALL                                               'str_repeat'
         48        SEND_VAL                                                 '++'
         49        ADD                                              ~25     !1, 1
         50        SEND_VAL                                                 ~25
         51        DO_ICALL                                         $26     
         52        CONCAT                                           ~27     $26, '%3C%2Fli%3E'
         53        CONCAT                                           ~28     ~27, '%0A'
         54        ECHO                                                     ~28
   40    55        IS_EQUAL                                                 !1, 0
         56      > JMPZ                                                     ~29, ->58
         57    >   ECHO                                                     '%3C%2Ful%3E%0A'
   41    58    > > RETURN                                                   null

End of function foo

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

End of function __construct

Function addchild:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YFpZc
function name:  addChild
number of ops:  7
compiled vars:  !0 = $menuElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'array_push'
          2        FETCH_OBJ_W                                      $1      'children'
          3        SEND_REF                                                 $1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                                 
   13     6      > RETURN                                                   null

End of function addchild

End of class MenuElement.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.22 ms | 1411 KiB | 18 Q