3v4l.org

run code in 300+ 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:  24
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_FCALL                                               'implode'
         16        SEND_VAL                                                 '%2C'
         17        INIT_METHOD_CALL                                         !0, 'getChildren'
         18        SEND_VAL_EX                                              'A'
         19        DO_FCALL                                      0  $7      
         20        SEND_VAR                                                 $7
         21        DO_ICALL                                         $8      
         22        ECHO                                                     $8
   24    23      > 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.0.0


preferences:
154.33 ms | 1405 KiB | 15 Q