3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Sqltree { private $FlatTable, $paths; public function __construct($FlatTable) { $this->FlatTable = $FlatTable; } public function generateTable($tree) { $this->paths = array(); $this->path_recursion($tree, array()); print_r($paths); } private function path_recursion($tree, $parents) { //Path erzeugen $this->paths[] = array($tree, $tree, 0); foreach($parents as $parent) { $this->paths[] = array($parent['id'], $tree['id'], $parents['path_length']); $parents['path_length']++; } if(is_array($tree['children'])) { $parents = array('id' => $tree['id'], 'path_length' => 1); foreach($tree['children'] as $child) { $this->path_recursion($child, $parents); } } } public static function CreateTable($FlatTable) { $sql = "CREATE TABLE ClosureTable ( ancestor_id INT NOT NULL REFERENCES $FlatTable(id), descendant_id INT NOT NULL REFERENCES $FlatTable(id), path_length INT, PRIMARY KEY (ancestor_id, descendant_id) );"; sql::create($sql); } } $tree = array(array('id' => 1, 'children' => array(array('id' => 2, 'children' => array('id' => 4, 'children' => false)), array('id' => 3, 'children' => false)))); print_r($tree); $sqltree = new SqlTree('asd'); $sqltree->generateTable($tree); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/klltQ
function name:  (null)
number of ops:  12
compiled vars:  !0 = $tree, !1 = $sqltree
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, <array>
   37     1        INIT_FCALL                                               'print_r'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   38     4        NEW                                              $4      'SqlTree'
          5        SEND_VAL_EX                                              'asd'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $4
   39     8        INIT_METHOD_CALL                                         !1, 'generateTable'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
   40    11      > RETURN                                                   1

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

End of function __construct

Function generatetable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/klltQ
function name:  generateTable
number of ops:  11
compiled vars:  !0 = $tree, !1 = $paths
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ                                               'paths'
          2        OP_DATA                                                  <array>
    9     3        INIT_METHOD_CALL                                         'path_recursion'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0          
   10     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
   11    10      > RETURN                                                   null

End of function generatetable

Function path_recursion:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 39
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 39
Branch analysis from position: 22
filename:       /in/klltQ
function name:  path_recursion
number of ops:  40
compiled vars:  !0 = $tree, !1 = $parents, !2 = $parent, !3 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_ARRAY                                       ~6      !0
          3        ADD_ARRAY_ELEMENT                                ~6      !0
          4        ADD_ARRAY_ELEMENT                                ~6      0
          5        FETCH_OBJ_W                                      $4      'paths'
          6        ASSIGN_DIM                                               $4
          7        OP_DATA                                                  ~6
   15     8      > FE_RESET_R                                       $7      !1, ->22
          9    > > FE_FETCH_R                                               $7, !2, ->22
   16    10    >   FETCH_DIM_R                                      ~10     !2, 'id'
         11        INIT_ARRAY                                       ~11     ~10
         12        FETCH_DIM_R                                      ~12     !0, 'id'
         13        ADD_ARRAY_ELEMENT                                ~11     ~12
         14        FETCH_DIM_R                                      ~13     !1, 'path_length'
         15        ADD_ARRAY_ELEMENT                                ~11     ~13
         16        FETCH_OBJ_W                                      $8      'paths'
         17        ASSIGN_DIM                                               $8
         18        OP_DATA                                                  ~11
   17    19        FETCH_DIM_RW                                     $14     !1, 'path_length'
         20        PRE_INC                                                  $14
   15    21      > JMP                                                      ->9
         22    >   FE_FREE                                                  $7
   19    23        FETCH_DIM_R                                      ~16     !0, 'children'
         24        TYPE_CHECK                                  128          ~16
         25      > JMPZ                                                     ~17, ->39
   20    26    >   FETCH_DIM_R                                      ~18     !0, 'id'
         27        INIT_ARRAY                                       ~19     ~18, 'id'
         28        ADD_ARRAY_ELEMENT                                ~19     1, 'path_length'
         29        ASSIGN                                                   !1, ~19
   21    30        FETCH_DIM_R                                      ~21     !0, 'children'
         31      > FE_RESET_R                                       $22     ~21, ->38
         32    > > FE_FETCH_R                                               $22, !3, ->38
   22    33    >   INIT_METHOD_CALL                                         'path_recursion'
         34        SEND_VAR                                                 !3
         35        SEND_VAR                                                 !1
         36        DO_FCALL                                      0          
   21    37      > JMP                                                      ->32
         38    >   FE_FREE                                                  $22
   25    39    > > RETURN                                                   null

End of function path_recursion

Function createtable:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/klltQ
function name:  CreateTable
number of ops:  11
compiled vars:  !0 = $FlatTable, !1 = $sql
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        ROPE_INIT                                     5  ~3      'CREATE+TABLE+ClosureTable+%28%0A++++++++++ancestor_id+++INT+NOT+NULL+REFERENCES+'
   28     2        ROPE_ADD                                      1  ~3      ~3, !0
          3        ROPE_ADD                                      2  ~3      ~3, '%28id%29%2C%0A++++++++++descendant_id+INT+NOT+NULL+REFERENCES+'
   29     4        ROPE_ADD                                      3  ~3      ~3, !0
          5        ROPE_END                                      4  ~2      ~3, '%28id%29%2C%0A++++++++++path_length+INT%2C%0A++++++++++PRIMARY+KEY+%28ancestor_id%2C+descendant_id%29%0A++++++++%29%3B'
   27     6        ASSIGN                                                   !1, ~2
   33     7        INIT_STATIC_METHOD_CALL                                  'sql', 'create'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
   34    10      > RETURN                                                   null

End of function createtable

End of class Sqltree.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.98 ms | 1396 KiB | 15 Q