3v4l.org

run code in 300+ PHP versions simultaneously
<?php class XmlToArray { public function __construct() {} function xml2array($xml) { if (is_string($xml)) { $dom = new \DOMDocument; $v = $dom->loadXml($xml); if(!$v) {return false;} } return $this->_process($dom); } function _process($node) { $occurance = array(); $result = ""; if(isset($node->childNodes)) { foreach($node->childNodes as $child) { $occurance[$child->nodeName] = isset($occurance[$child->nodeName]) ? $occurance[$child->nodeName] + 1 : 1; } } if($node->nodeType == XML_TEXT_NODE) { $result = html_entity_decode(htmlentities($node->nodeValue, ENT_COMPAT, 'UTF-8'), ENT_COMPAT,'ISO-8859-15'); } else if($node->nodeType == XML_CDATA_SECTION_NODE){ $result = $node->nodeValue; } else { if($node->hasChildNodes()){ $children = $node->childNodes; for($i=0; $i<$children->length; $i++) { $child = $children->item($i); if ($child->nodeName == '#text' || $child->nodeName == '#cdata-section') { $text = $this->_process($child); if (trim($text) != '') { $result['#data'] = $this->_process($child); } } else { $result[$child->nodeName][] = $this->_process($child); } } } if($node->hasAttributes()) { $attributes = $node->attributes; if(!is_null($attributes)) { foreach ($attributes as $key => $attr) { $result["@".$attr->name] = $attr->value; } } } } return $result; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iJqE7
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E > > RETURN                                                   1

Class XmlToArray:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iJqE7
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   null

End of function __construct

Function xml2array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/iJqE7
function name:  xml2array
number of ops:  18
compiled vars:  !0 = $xml, !1 = $dom, !2 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~3, ->13
    9     3    >   NEW                                              $4      'DOMDocument'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $4
   10     6        INIT_METHOD_CALL                                         !1, 'loadXml'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $7      
          9        ASSIGN                                                   !2, $7
   11    10        BOOL_NOT                                         ~9      !2
         11      > JMPZ                                                     ~9, ->13
         12    > > RETURN                                                   <false>
   13    13    >   INIT_METHOD_CALL                                         '_process'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $10     
         16      > RETURN                                                   $10
   14    17*     > RETURN                                                   null

End of function xml2array

Function _process:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 38
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 88
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 51
Branch analysis from position: 88
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 106
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 106
Branch analysis from position: 96
2 jumps found. (Code = 77) Position 1 = 97, Position 2 = 105
Branch analysis from position: 97
2 jumps found. (Code = 78) Position 1 = 98, Position 2 = 105
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 105
Branch analysis from position: 106
Branch analysis from position: 106
Branch analysis from position: 51
2 jumps found. (Code = 47) Position 1 = 58, Position 2 = 61
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 77
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 76
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 51
Branch analysis from position: 88
Branch analysis from position: 51
Branch analysis from position: 76
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 88, Position 2 = 51
Branch analysis from position: 88
Branch analysis from position: 51
Branch analysis from position: 61
Branch analysis from position: 88
Branch analysis from position: 21
Branch analysis from position: 22
filename:       /in/iJqE7
function name:  _process
number of ops:  108
compiled vars:  !0 = $node, !1 = $occurance, !2 = $result, !3 = $child, !4 = $children, !5 = $i, !6 = $text, !7 = $attributes, !8 = $attr, !9 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, ''
   19     3        ISSET_ISEMPTY_PROP_OBJ                                   !0, 'childNodes'
          4      > JMPZ                                                     ~12, ->22
   20     5    >   FETCH_OBJ_R                                      ~13     !0, 'childNodes'
          6      > FE_RESET_R                                       $14     ~13, ->21
          7    > > FE_FETCH_R                                               $14, !3, ->21
   21     8    >   FETCH_OBJ_R                                      ~15     !3, 'nodeName'
          9        FETCH_OBJ_R                                      ~17     !3, 'nodeName'
         10        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~17
         11      > JMPZ                                                     ~18, ->17
         12    >   FETCH_OBJ_R                                      ~19     !3, 'nodeName'
         13        FETCH_DIM_R                                      ~20     !1, ~19
         14        ADD                                              ~21     ~20, 1
         15        QM_ASSIGN                                        ~22     ~21
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~22     1
         18    >   ASSIGN_DIM                                               !1, ~15
         19        OP_DATA                                                  ~22
   20    20      > JMP                                                      ->7
         21    >   FE_FREE                                                  $14
   25    22    >   FETCH_OBJ_R                                      ~23     !0, 'nodeType'
         23        IS_EQUAL                                                 ~23, 3
         24      > JMPZ                                                     ~24, ->38
   26    25    >   INIT_FCALL                                               'html_entity_decode'
         26        INIT_FCALL                                               'htmlentities'
         27        FETCH_OBJ_R                                      ~25     !0, 'nodeValue'
         28        SEND_VAL                                                 ~25
         29        SEND_VAL                                                 2
         30        SEND_VAL                                                 'UTF-8'
         31        DO_ICALL                                         $26     
         32        SEND_VAR                                                 $26
         33        SEND_VAL                                                 2
         34        SEND_VAL                                                 'ISO-8859-15'
         35        DO_ICALL                                         $27     
         36        ASSIGN                                                   !2, $27
         37      > JMP                                                      ->106
   28    38    >   FETCH_OBJ_R                                      ~29     !0, 'nodeType'
         39        IS_EQUAL                                                 ~29, 4
         40      > JMPZ                                                     ~30, ->44
   29    41    >   FETCH_OBJ_R                                      ~31     !0, 'nodeValue'
         42        ASSIGN                                                   !2, ~31
         43      > JMP                                                      ->106
   32    44    >   INIT_METHOD_CALL                                         !0, 'hasChildNodes'
         45        DO_FCALL                                      0  $33     
         46      > JMPZ                                                     $33, ->88
   33    47    >   FETCH_OBJ_R                                      ~34     !0, 'childNodes'
         48        ASSIGN                                                   !4, ~34
   34    49        ASSIGN                                                   !5, 0
         50      > JMP                                                      ->85
   35    51    >   INIT_METHOD_CALL                                         !4, 'item'
         52        SEND_VAR_EX                                              !5
         53        DO_FCALL                                      0  $37     
         54        ASSIGN                                                   !3, $37
   36    55        FETCH_OBJ_R                                      ~39     !3, 'nodeName'
         56        IS_EQUAL                                         ~40     ~39, '%23text'
         57      > JMPNZ_EX                                         ~40     ~40, ->61
         58    >   FETCH_OBJ_R                                      ~41     !3, 'nodeName'
         59        IS_EQUAL                                         ~42     ~41, '%23cdata-section'
         60        BOOL                                             ~40     ~42
         61    > > JMPZ                                                     ~40, ->77
   37    62    >   INIT_METHOD_CALL                                         '_process'
         63        SEND_VAR_EX                                              !3
         64        DO_FCALL                                      0  $43     
         65        ASSIGN                                                   !6, $43
   38    66        INIT_FCALL                                               'trim'
         67        SEND_VAR                                                 !6
         68        DO_ICALL                                         $45     
         69        IS_NOT_EQUAL                                             $45, ''
         70      > JMPZ                                                     ~46, ->76
   39    71    >   INIT_METHOD_CALL                                         '_process'
         72        SEND_VAR_EX                                              !3
         73        DO_FCALL                                      0  $48     
         74        ASSIGN_DIM                                               !2, '%23data'
         75        OP_DATA                                                  $48
         76    > > JMP                                                      ->84
   43    77    >   FETCH_OBJ_R                                      ~49     !3, 'nodeName'
         78        INIT_METHOD_CALL                                         '_process'
         79        SEND_VAR_EX                                              !3
         80        DO_FCALL                                      0  $52     
         81        FETCH_DIM_W                                      $50     !2, ~49
         82        ASSIGN_DIM                                               $50
         83        OP_DATA                                                  $52
   34    84    >   PRE_INC                                                  !5
         85    >   FETCH_OBJ_R                                      ~54     !4, 'length'
         86        IS_SMALLER                                               !5, ~54
         87      > JMPNZ                                                    ~55, ->51
   47    88    >   INIT_METHOD_CALL                                         !0, 'hasAttributes'
         89        DO_FCALL                                      0  $56     
         90      > JMPZ                                                     $56, ->106
   48    91    >   FETCH_OBJ_R                                      ~57     !0, 'attributes'
         92        ASSIGN                                                   !7, ~57
   49    93        TYPE_CHECK                                    2  ~59     !7
         94        BOOL_NOT                                         ~60     ~59
         95      > JMPZ                                                     ~60, ->106
   50    96    > > FE_RESET_R                                       $61     !7, ->105
         97    > > FE_FETCH_R                                       ~62     $61, !8, ->105
         98    >   ASSIGN                                                   !9, ~62
   51    99        FETCH_OBJ_R                                      ~64     !8, 'name'
        100        CONCAT                                           ~65     '%40', ~64
        101        FETCH_OBJ_R                                      ~67     !8, 'value'
        102        ASSIGN_DIM                                               !2, ~65
        103        OP_DATA                                                  ~67
   50   104      > JMP                                                      ->97
        105    >   FE_FREE                                                  $61
   56   106    > > RETURN                                                   !2
   57   107*     > RETURN                                                   null

End of function _process

End of class XmlToArray.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.79 ms | 1408 KiB | 19 Q