3v4l.org

run code in 500+ PHP versions simultaneously
<?php class CategoryTree { private $categories = []; public function addCategory(string $category, string $parent = null): void { $this->categories[$parent][] = $category; } public function getChildren(string $parent): array { return $this->categories[$parent]; } } $c = new CategoryTree; $c->addCategory('A', null); $c->addCategory('B', 'A'); $c->addCategory('C', 'A'); echo implode(',', $c->getChildren('A')); //Result should be "B,C" or "C,B"
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LoQ0i
function name:  (null)
number of ops:  21
compiled vars:  !0 = $c
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   NEW                                                  $1      'CategoryTree'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   20     3        INIT_METHOD_CALL                                             !0, 'addCategory'
          4        SEND_VAL_EX                                                  'A'
          5        SEND_VAL_EX                                                  null
          6        DO_FCALL                                          0          
   21     7        INIT_METHOD_CALL                                             !0, 'addCategory'
          8        SEND_VAL_EX                                                  'B'
          9        SEND_VAL_EX                                                  'A'
         10        DO_FCALL                                          0          
   22    11        INIT_METHOD_CALL                                             !0, 'addCategory'
         12        SEND_VAL_EX                                                  'C'
         13        SEND_VAL_EX                                                  'A'
         14        DO_FCALL                                          0          
   23    15        INIT_METHOD_CALL                                             !0, 'getChildren'
         16        SEND_VAL_EX                                                  'A'
         17        DO_FCALL                                          0  $7      
         18        FRAMELESS_ICALL_2                implode             ~8      '%2C', $7
         19        ECHO                                                         ~8
   24    20      > RETURN                                                       1

Class CategoryTree:
Function addcategory:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LoQ0i
function name:  addCategory
number of ops:  7
compiled vars:  !0 = $category, !1 = $parent
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      null
    9     2        FETCH_OBJ_W                                          $2      'categories'
          3        FETCH_DIM_W                                          $3      $2, !1
          4        ASSIGN_DIM                                                   $3
          5        OP_DATA                                                      !0
   10     6      > RETURN                                                       null

End of function addcategory

Function getchildren:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LoQ0i
function name:  getChildren
number of ops:  7
compiled vars:  !0 = $parent
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
   15     1        FETCH_OBJ_R                                          ~1      'categories'
          2        FETCH_DIM_R                                          ~2      ~1, !0
          3        VERIFY_RETURN_TYPE                                           ~2
          4      > RETURN                                                       ~2
   16     5*       VERIFY_RETURN_TYPE                                           
          6*     > RETURN                                                       null

End of function getchildren

End of class CategoryTree.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
217.56 ms | 1987 KiB | 13 Q