3v4l.org

run code in 300+ PHP versions simultaneously
<?php class category { public $name; public $subCats = array(); public function __construct($name = "") { $this->name = $name; } public function add_sub_cat($subCat) { array_push($this->subCats, $subCat); } } function tree_print($root_category) { $stack = array(array($root_category)); echo '<ul>'."\n"; while (count($stack)) { $category = array_shift($stack[count($stack)-1]); echo '<li><div id="category-name"><p>' . $category->name . '</p></div></li>'."\n"; echo '<ul>'."\n"; $stack[] = $category->subCats; while (count($stack) && count($stack[count($stack)-1]) == 0) { echo '</ul>'."\n"; array_pop($stack); } } } $x = new category('root'); $x->add_sub_cat(new category('foo')); $x->add_sub_cat(new category('bar')); $x->subCats[0]->add_sub_cat(new category('baz')); $x->subCats[1]->add_sub_cat(new category('baz2')); tree_print($x);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/umpvf
function name:  (null)
number of ops:  36
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   NEW                                              $1      'category'
          1        SEND_VAL_EX                                              'root'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   31     4        INIT_METHOD_CALL                                         !0, 'add_sub_cat'
          5        NEW                                              $4      'category'
          6        SEND_VAL_EX                                              'foo'
          7        DO_FCALL                                      0          
          8        SEND_VAR_NO_REF_EX                                       $4
          9        DO_FCALL                                      0          
   32    10        INIT_METHOD_CALL                                         !0, 'add_sub_cat'
         11        NEW                                              $7      'category'
         12        SEND_VAL_EX                                              'bar'
         13        DO_FCALL                                      0          
         14        SEND_VAR_NO_REF_EX                                       $7
         15        DO_FCALL                                      0          
   33    16        FETCH_OBJ_R                                      ~10     !0, 'subCats'
         17        FETCH_DIM_R                                      ~11     ~10, 0
         18        INIT_METHOD_CALL                                         ~11, 'add_sub_cat'
         19        NEW                                              $12     'category'
         20        SEND_VAL_EX                                              'baz'
         21        DO_FCALL                                      0          
         22        SEND_VAR_NO_REF_EX                                       $12
         23        DO_FCALL                                      0          
   34    24        FETCH_OBJ_R                                      ~15     !0, 'subCats'
         25        FETCH_DIM_R                                      ~16     ~15, 1
         26        INIT_METHOD_CALL                                         ~16, 'add_sub_cat'
         27        NEW                                              $17     'category'
         28        SEND_VAL_EX                                              'baz2'
         29        DO_FCALL                                      0          
         30        SEND_VAR_NO_REF_EX                                       $17
         31        DO_FCALL                                      0          
   36    32        INIT_FCALL                                               'tree_print'
         33        SEND_VAR                                                 !0
         34        DO_FCALL                                      0          
         35      > RETURN                                                   1

Function tree_print:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 6
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 23
Branch analysis from position: 36
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
Branch analysis from position: 35
Branch analysis from position: 35
filename:       /in/umpvf
function name:  tree_print
number of ops:  39
compiled vars:  !0 = $root_category, !1 = $stack, !2 = $category
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_ARRAY                                       ~3      !0
          2        INIT_ARRAY                                       ~4      ~3
          3        ASSIGN                                                   !1, ~4
   17     4        ECHO                                                     '%3Cul%3E%0A'
   18     5      > JMP                                                      ->36
   19     6    >   INIT_FCALL                                               'array_shift'
          7        COUNT                                            ~6      !1
          8        SUB                                              ~7      ~6, 1
          9        FETCH_DIM_W                                      $8      !1, ~7
         10        SEND_REF                                                 $8
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !2, $9
   20    13        FETCH_OBJ_R                                      ~11     !2, 'name'
         14        CONCAT                                           ~12     '%3Cli%3E%3Cdiv+id%3D%22category-name%22%3E%3Cp%3E', ~11
         15        CONCAT                                           ~13     ~12, '%3C%2Fp%3E%3C%2Fdiv%3E%3C%2Fli%3E'
         16        CONCAT                                           ~14     ~13, '%0A'
         17        ECHO                                                     ~14
   21    18        ECHO                                                     '%3Cul%3E%0A'
   22    19        FETCH_OBJ_R                                      ~16     !2, 'subCats'
         20        ASSIGN_DIM                                               !1
         21        OP_DATA                                                  ~16
   23    22      > JMP                                                      ->27
   24    23    >   ECHO                                                     '%3C%2Ful%3E%0A'
   25    24        INIT_FCALL                                               'array_pop'
         25        SEND_REF                                                 !1
         26        DO_ICALL                                                 
   23    27    >   COUNT                                            ~18     !1
         28      > JMPZ_EX                                          ~18     ~18, ->35
         29    >   COUNT                                            ~19     !1
         30        SUB                                              ~20     ~19, 1
         31        FETCH_DIM_R                                      ~21     !1, ~20
         32        COUNT                                            ~22     ~21
         33        IS_EQUAL                                         ~23     ~22, 0
         34        BOOL                                             ~18     ~23
         35    > > JMPNZ                                                    ~18, ->23
   18    36    >   COUNT                                            ~24     !1
         37      > JMPNZ                                                    ~24, ->6
   28    38    > > RETURN                                                   null

End of function tree_print

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

End of function __construct

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

End of function add_sub_cat

End of class category.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
132.1 ms | 1411 KiB | 20 Q