3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayToXml($data, \SimpleXmlElement $element, $parent = null) { foreach ($data as $key => $value) { if (is_array($value) || $value instanceof \Traversable) { if (!is_numeric($key)) { if (count($value) > 0 && isset($value[0])) { arrayToXml($value, $element, $key); } else { $subnode = $element->addChild($key); arrayToXml($value, $subnode, $key); } } else { $subnode = $element->addChild($parent); arrayToXml($value, $subnode, $parent); } } else { if (!is_numeric($key)) { if (substr($key, 0, 1) === '@') { $element->addAttribute(substr($key, 1), $value); } elseif ($key === 'value' and count($data) === 1) { $element[0] = $value; } elseif (is_bool($value)) { $element->addChild($key, intval($value)); } else { $element->addChild($key, htmlspecialchars($value, ENT_QUOTES)); } } else { $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES)); } } } } $data = array(); $doc = new \SimpleXMLElement('<resource href="/"/>'); arrayToXml($data, $doc); echo $doc->asXml(); //$xml = new \SimpleXMLElement('<resource href="/"><x><0>test</0></x></resource>'); //echo $xml->x;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jfHgp
function name:  (null)
number of ops:  13
compiled vars:  !0 = $data, !1 = $doc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, <array>
   36     1        NEW                                              $3      'SimpleXMLElement'
          2        SEND_VAL_EX                                              '%3Cresource+href%3D%22%2F%22%2F%3E'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
   38     5        INIT_FCALL                                               'arraytoxml'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0          
   40     9        INIT_METHOD_CALL                                         !1, 'asXml'
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
   42    12      > RETURN                                                   1

Function arraytoxml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 104
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 104
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 48
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 28
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 21
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 95
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 69
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 69
2 jumps found. (Code = 46) Position 1 = 71, Position 2 = 74
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 78
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 86
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 74
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
filename:       /in/jfHgp
function name:  arrayToXml
number of ops:  106
compiled vars:  !0 = $data, !1 = $element, !2 = $parent, !3 = $value, !4 = $key, !5 = $subnode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    4     3      > FE_RESET_R                                       $6      !0, ->104
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->104
          5    >   ASSIGN                                                   !4, ~7
    5     6        TYPE_CHECK                                  128  ~9      !3
          7      > JMPNZ_EX                                         ~9      ~9, ->10
          8    >   INSTANCEOF                                       ~10     !3, 'Traversable'
          9        BOOL                                             ~9      ~10
         10    > > JMPZ                                                     ~9, ->48
    6    11    >   INIT_FCALL                                               'is_numeric'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $11     
         14        BOOL_NOT                                         ~12     $11
         15      > JMPZ                                                     ~12, ->38
    7    16    >   COUNT                                            ~13     !3
         17        IS_SMALLER                                       ~14     0, ~13
         18      > JMPZ_EX                                          ~14     ~14, ->21
         19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !3, 0
         20        BOOL                                             ~14     ~15
         21    > > JMPZ                                                     ~14, ->28
    8    22    >   INIT_FCALL_BY_NAME                                       'arrayToXml'
         23        SEND_VAR_EX                                              !3
         24        SEND_VAR_EX                                              !1
         25        SEND_VAR_EX                                              !4
         26        DO_FCALL                                      0          
         27      > JMP                                                      ->37
   10    28    >   INIT_METHOD_CALL                                         !1, 'addChild'
         29        SEND_VAR_EX                                              !4
         30        DO_FCALL                                      0  $17     
         31        ASSIGN                                                   !5, $17
   11    32        INIT_FCALL_BY_NAME                                       'arrayToXml'
         33        SEND_VAR_EX                                              !3
         34        SEND_VAR_EX                                              !5
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0          
         37    > > JMP                                                      ->47
   14    38    >   INIT_METHOD_CALL                                         !1, 'addChild'
         39        SEND_VAR_EX                                              !2
         40        DO_FCALL                                      0  $20     
         41        ASSIGN                                                   !5, $20
   15    42        INIT_FCALL_BY_NAME                                       'arrayToXml'
         43        SEND_VAR_EX                                              !3
         44        SEND_VAR_EX                                              !5
         45        SEND_VAR_EX                                              !2
         46        DO_FCALL                                      0          
         47    > > JMP                                                      ->103
   18    48    >   INIT_FCALL                                               'is_numeric'
         49        SEND_VAR                                                 !4
         50        DO_ICALL                                         $23     
         51        BOOL_NOT                                         ~24     $23
         52      > JMPZ                                                     ~24, ->95
   19    53    >   INIT_FCALL                                               'substr'
         54        SEND_VAR                                                 !4
         55        SEND_VAL                                                 0
         56        SEND_VAL                                                 1
         57        DO_ICALL                                         $25     
         58        IS_IDENTICAL                                             $25, '%40'
         59      > JMPZ                                                     ~26, ->69
   20    60    >   INIT_METHOD_CALL                                         !1, 'addAttribute'
         61        INIT_FCALL                                               'substr'
         62        SEND_VAR                                                 !4
         63        SEND_VAL                                                 1
         64        DO_ICALL                                         $27     
         65        SEND_VAR_NO_REF_EX                                       $27
         66        SEND_VAR_EX                                              !3
         67        DO_FCALL                                      0          
         68      > JMP                                                      ->94
   21    69    >   IS_IDENTICAL                                     ~29     !4, 'value'
         70      > JMPZ_EX                                          ~29     ~29, ->74
         71    >   COUNT                                            ~30     !0
         72        IS_IDENTICAL                                     ~31     ~30, 1
         73        BOOL                                             ~29     ~31
         74    > > JMPZ                                                     ~29, ->78
   22    75    >   ASSIGN_DIM                                               !1, 0
         76        OP_DATA                                                  !3
         77      > JMP                                                      ->94
   23    78    >   TYPE_CHECK                                   12          !3
         79      > JMPZ                                                     ~33, ->86
   24    80    >   INIT_METHOD_CALL                                         !1, 'addChild'
         81        SEND_VAR_EX                                              !4
         82        CAST                                          4  ~34     !3
         83        SEND_VAL_EX                                              ~34
         84        DO_FCALL                                      0          
         85      > JMP                                                      ->94
   26    86    >   INIT_METHOD_CALL                                         !1, 'addChild'
         87        SEND_VAR_EX                                              !4
         88        INIT_FCALL                                               'htmlspecialchars'
         89        SEND_VAR                                                 !3
         90        SEND_VAL                                                 3
         91        DO_ICALL                                         $36     
         92        SEND_VAR_NO_REF_EX                                       $36
         93        DO_FCALL                                      0          
         94    > > JMP                                                      ->103
   29    95    >   INIT_METHOD_CALL                                         !1, 'addChild'
         96        SEND_VAR_EX                                              !2
         97        INIT_FCALL                                               'htmlspecialchars'
         98        SEND_VAR                                                 !3
         99        SEND_VAL                                                 3
        100        DO_ICALL                                         $38     
        101        SEND_VAR_NO_REF_EX                                       $38
        102        DO_FCALL                                      0          
    4   103    > > JMP                                                      ->4
        104    >   FE_FREE                                                  $6
   33   105      > RETURN                                                   null

End of function arraytoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.54 ms | 1410 KiB | 20 Q