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); $simpleXmlObj = _fixVersionDifferences($simpleXmlObj); $array = _simpleXmlObj2Array($simpleXmlObj); return $array; } function _fixVersionDifferences($simpleXmlObj) { $simpleXmlObj = _fixEmptyStringDifference($simpleXmlObj); return $simpleXmlObj; } function _fixEmptyStringDifference($simpleXmlObj, $z=0) { foreach (array_keys((array)$simpleXmlObj) as $key => $element) { $el = (array)$simpleXmlObj->$element; if(isset($el[0])){ print_r($el[0]); $trim = trim($el[0]); echo '>>>';print_r($trim);echo '<<<'; if (empty($trim) && $trim !== 0) { unset($simpleXmlObj->$element); } }else{ $simpleXmlObj->$element = _fixEmptyStringDifference($simpleXmlObj->$element, $z+1); } } 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/IQFh6
function name:  (null)
number of ops:  14
compiled vars:  !0 = $n, !1 = $xml, !2 = $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
   46     5        ASSIGN                                                   !1, '%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'
   56     6        INIT_FCALL                                               'convert'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !2, $6
   57    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function convert:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQFh6
function name:  convert
number of ops:  15
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                                       '_fixVersionDifferences'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !1, $5
   11     9        INIT_FCALL_BY_NAME                                       '_simpleXmlObj2Array'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0  $7      
         12        ASSIGN                                                   !2, $7
   12    13      > RETURN                                                   !2
   13    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/IQFh6
function name:  _fixVersionDifferences
number of ops:  7
compiled vars:  !0 = $simpleXmlObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        INIT_FCALL_BY_NAME                                       '_fixEmptyStringDifference'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   18     5      > RETURN                                                   !0
   19     6*     > RETURN                                                   null

End of function _fixversiondifferences

Function _fixemptystringdifference:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 45
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 45
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 35
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 34
Branch analysis from position: 32
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/IQFh6
function name:  _fixEmptyStringDifference
number of ops:  48
compiled vars:  !0 = $simpleXmlObj, !1 = $z, !2 = $element, !3 = $key, !4 = $el, !5 = $trim
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   23     2        INIT_FCALL                                               'array_keys'
          3        CAST                                          7  ~6      !0
          4        SEND_VAL                                                 ~6
          5        DO_ICALL                                         $7      
          6      > FE_RESET_R                                       $8      $7, ->45
          7    > > FE_FETCH_R                                       ~9      $8, !2, ->45
          8    >   ASSIGN                                                   !3, ~9
   24     9        FETCH_OBJ_R                                      ~11     !0, !2
         10        CAST                                          7  ~12     ~11
         11        ASSIGN                                                   !4, ~12
   25    12        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 0
         13      > JMPZ                                                     ~14, ->35
   26    14    >   INIT_FCALL                                               'print_r'
         15        FETCH_DIM_R                                      ~15     !4, 0
         16        SEND_VAL                                                 ~15
         17        DO_ICALL                                                 
   27    18        INIT_FCALL                                               'trim'
         19        FETCH_DIM_R                                      ~17     !4, 0
         20        SEND_VAL                                                 ~17
         21        DO_ICALL                                         $18     
         22        ASSIGN                                                   !5, $18
   28    23        ECHO                                                     '%3E%3E%3E'
         24        INIT_FCALL                                               'print_r'
         25        SEND_VAR                                                 !5
         26        DO_ICALL                                                 
         27        ECHO                                                     '%3C%3C%3C'
   30    28        ISSET_ISEMPTY_CV                                 ~21     !5
         29      > JMPZ_EX                                          ~21     ~21, ->32
         30    >   IS_NOT_IDENTICAL                                 ~22     !5, 0
         31        BOOL                                             ~21     ~22
         32    > > JMPZ                                                     ~21, ->34
   31    33    >   UNSET_OBJ                                                !0, !2
         34    > > JMP                                                      ->44
   34    35    >   INIT_FCALL_BY_NAME                                       '_fixEmptyStringDifference'
         36        CHECK_FUNC_ARG                                           
         37        FETCH_OBJ_FUNC_ARG                               $24     !0, !2
         38        SEND_FUNC_ARG                                            $24
         39        ADD                                              ~25     !1, 1
         40        SEND_VAL_EX                                              ~25
         41        DO_FCALL                                      0  $26     
         42        ASSIGN_OBJ                                               !0, !2
         43        OP_DATA                                                  $26
   23    44    > > JMP                                                      ->7
         45    >   FE_FREE                                                  $8
   37    46      > RETURN                                                   !0
   38    47*     > 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/IQFh6
function name:  _simpleXmlObj2Array
number of ops:  10
compiled vars:  !0 = $simpleXmlObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   43     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
   44     9*     > RETURN                                                   null

End of function _simplexmlobj2array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.64 ms | 1407 KiB | 28 Q