3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convert($xml) { $simpleXmlObj = simplexml_load_string($xml); $simpleXmlObj = _fixVersionDifferences($simpleXmlObj); $array = _simpleXmlObj2Array($simpleXmlObj); return $array; } function _fixVersionDifferences($simpleXmlObj) { $simpleXmlObj = _fixEmptyStringDifference($simpleXmlObj); return $simpleXmlObj; } function _fixEmptyStringDifference($simpleXmlObj) { foreach (get_object_vars($simpleXmlObj) as $key => $element) { if ($element instanceof \SimpleXMLElement) { $simpleXmlObj->$key = _fixEmptyStringDifference($element); } if ($element != 0 && empty($element)) { unset($simpleXmlObj->$key); } } return $simpleXmlObj; } function _simpleXmlObj2Array($simpleXmlObj) { //Maybe it is not fast but the easiest way to convert return json_decode(json_encode($simpleXmlObj), TRUE); } $xml = <<<xml <?xml version="1.0" encoding="utf-8"?> <RESPONSE> <SUCCESS>true</SUCCESS> <ERRORMESSAGE> </ERRORMESSAGE> <TIMESTAMP>21/09/2015 03:26:37</TIMESTAMP> </RESPONSE> xml; $response = convert($xml); print_r($response);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLpZu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $xml, !1 = $response
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3CRESPONSE%3E%0A++%3CSUCCESS%3Etrue%3C%2FSUCCESS%3E%0A++%3CERRORMESSAGE%3E%0A++%3C%2FERRORMESSAGE%3E%0A++%3CTIMESTAMP%3E21%2F09%2F2015+03%3A26%3A37%3C%2FTIMESTAMP%3E%0A%3C%2FRESPONSE%3E'
   46     1        INIT_FCALL                                               'convert'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   49     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

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

End of function convert

Function _fixversiondifferences:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLpZu
function name:  _fixVersionDifferences
number of ops:  7
compiled vars:  !0 = $simpleXmlObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_FCALL_BY_NAME                                       '_fixEmptyStringDifference'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   14     5      > RETURN                                                   !0
   15     6*     > RETURN                                                   null

End of function _fixversiondifferences

Function _fixemptystringdifference:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 21
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 20
Branch analysis from position: 18
Branch analysis from position: 14
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/lLpZu
function name:  _fixEmptyStringDifference
number of ops:  24
compiled vars:  !0 = $simpleXmlObj, !1 = $element, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'get_object_vars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4      > FE_RESET_R                                       $4      $3, ->21
          5    > > FE_FETCH_R                                       ~5      $4, !1, ->21
          6    >   ASSIGN                                                   !2, ~5
   20     7        INSTANCEOF                                               !1, 'SimpleXMLElement'
          8      > JMPZ                                                     ~7, ->14
   21     9    >   INIT_FCALL_BY_NAME                                       '_fixEmptyStringDifference'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0  $9      
         12        ASSIGN_OBJ                                               !0, !2
         13        OP_DATA                                                  $9
   23    14    >   IS_NOT_EQUAL                                     ~10     !1, 0
         15      > JMPZ_EX                                          ~10     ~10, ->18
         16    >   ISSET_ISEMPTY_CV                                 ~11     !1
         17        BOOL                                             ~10     ~11
         18    > > JMPZ                                                     ~10, ->20
   24    19    >   UNSET_OBJ                                                !0, !2
   19    20    > > JMP                                                      ->5
         21    >   FE_FREE                                                  $4
   27    22      > RETURN                                                   !0
   28    23*     > RETURN                                                   null

End of function _fixemptystringdifference

Function _simplexmlobj2array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lLpZu
function name:  _simpleXmlObj2Array
number of ops:  10
compiled vars:  !0 = $simpleXmlObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'json_decode'
          2        INIT_FCALL                                               'json_encode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $2      
          8      > RETURN                                                   $2
   34     9*     > RETURN                                                   null

End of function _simplexmlobj2array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.74 ms | 1407 KiB | 24 Q