3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); global $n; $n = 0; function convert($xml) { $simpleXmlObj = simplexml_load_string($xml); $array = toarray($simpleXmlObj); return $array; } function toarray($simpleXmlObj) { $simpleXmlObjNew = array(); foreach (array_keys((array) $simpleXmlObj) as $element) { $el = (array) $simpleXmlObj->$element; if (isset($el[0])) { if (is_object($el[0])) { $r = (array) $el[0]; if (isset($r[0])) { $el[0] = $r[0]; } } $trim = $el[0]; $simpleXmlObjNew[$element] = $trim; } else { $simpleXmlObjNew[$element] = toarray($simpleXmlObj->$element); } if (empty($simpleXmlObjNew[$element])) { $simpleXmlObjNew[$element] = ''; } } return $simpleXmlObjNew; } $xml = <<<xml <?xml version="1.0" encoding="utf-8"?> <RESPONSE> <e></e> <e1> </e1> <e2> s </e2> <e3>s</e3> <e4> </e4> </RESPONSE> xml; $simpleXmlObj = simplexml_load_string($xml); $response = toarray($simpleXmlObj); print_r($response);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QiQ45
function name:  (null)
number of ops:  18
compiled vars:  !0 = $n, !1 = $xml, !2 = $simpleXmlObj, !3 = $response
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 32767
          2        DO_ICALL                                                 
    4     3        BIND_GLOBAL                                              !0, 'n'
    5     4        ASSIGN                                                   !0, 0
   39     5        ASSIGN                                                   !1, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3CRESPONSE%3E%0A++%3Ce%3E%3C%2Fe%3E%0A++%3Ce1%3E++%3C%2Fe1%3E%0A++%3Ce2%3E+s+%3C%2Fe2%3E%0A++%3Ce3%3Es%3C%2Fe3%3E%0A++%3Ce4%3E%0A++%3C%2Fe4%3E%0A%3C%2FRESPONSE%3E'
   51     6        INIT_FCALL                                               'simplexml_load_string'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !2, $7
   52    10        INIT_FCALL                                               'toarray'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !3, $9
   53    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function convert:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QiQ45
function name:  convert
number of ops:  11
compiled vars:  !0 = $xml, !1 = $simpleXmlObj, !2 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'simplexml_load_string'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !1, $3
   10     5        INIT_FCALL_BY_NAME                                       'toarray'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !2, $5
   11     9      > RETURN                                                   !2
   12    10*     > RETURN                                                   null

End of function convert

Function toarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 41
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 41
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 29
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 40
Branch analysis from position: 24
Branch analysis from position: 24
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
Branch analysis from position: 40
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/QiQ45
function name:  toarray
number of ops:  44
compiled vars:  !0 = $simpleXmlObj, !1 = $simpleXmlObjNew, !2 = $element, !3 = $el, !4 = $r, !5 = $trim
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        ASSIGN                                                   !1, <array>
   17     2        INIT_FCALL                                               'array_keys'
          3        CAST                                          7  ~7      !0
          4        SEND_VAL                                                 ~7
          5        DO_ICALL                                         $8      
          6      > FE_RESET_R                                       $9      $8, ->41
          7    > > FE_FETCH_R                                               $9, !2, ->41
   18     8    >   FETCH_OBJ_R                                      ~10     !0, !2
          9        CAST                                          7  ~11     ~10
         10        ASSIGN                                                   !3, ~11
   20    11        ISSET_ISEMPTY_DIM_OBJ                         0          !3, 0
         12      > JMPZ                                                     ~13, ->29
   21    13    >   FETCH_DIM_R                                      ~14     !3, 0
         14        TYPE_CHECK                                  256          ~14
         15      > JMPZ                                                     ~15, ->24
   22    16    >   FETCH_DIM_R                                      ~16     !3, 0
         17        CAST                                          7  ~17     ~16
         18        ASSIGN                                                   !4, ~17
   23    19        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 0
         20      > JMPZ                                                     ~19, ->24
   24    21    >   FETCH_DIM_R                                      ~21     !4, 0
         22        ASSIGN_DIM                                               !3, 0
         23        OP_DATA                                                  ~21
   27    24    >   FETCH_DIM_R                                      ~22     !3, 0
         25        ASSIGN                                                   !5, ~22
   28    26        ASSIGN_DIM                                               !1, !2
         27        OP_DATA                                                  !5
         28      > JMP                                                      ->36
   30    29    >   INIT_FCALL_BY_NAME                                       'toarray'
         30        CHECK_FUNC_ARG                                           
         31        FETCH_OBJ_FUNC_ARG                               $26     !0, !2
         32        SEND_FUNC_ARG                                            $26
         33        DO_FCALL                                      0  $27     
         34        ASSIGN_DIM                                               !1, !2
         35        OP_DATA                                                  $27
   32    36    >   ISSET_ISEMPTY_DIM_OBJ                         1          !1, !2
         37      > JMPZ                                                     ~28, ->40
   33    38    >   ASSIGN_DIM                                               !1, !2
         39        OP_DATA                                                  ''
   17    40    > > JMP                                                      ->7
         41    >   FE_FREE                                                  $9
   36    42      > RETURN                                                   !1
   37    43*     > RETURN                                                   null

End of function toarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.12 ms | 1407 KiB | 22 Q