3v4l.org

run code in 200+ PHP versions simultaneously
<?php $xml_1 = '<namesilo> <request> <operation>getDomainInfo</operation> <ip>55.555.55.55</ip> </request> <reply> <code>300</code> <detail>success</detail> <created>2009-01-11</created> <expires>2017-01-11</expires> <status>Active</status> <locked>Yes</locked> <private>Yes</private> <auto_renew>Yes</auto_renew> <traffic_type>Forwarded</traffic_type> <email_verification_required>No</email_verification_required> <portfolio>Main Portfolio</portfolio> <forward_url>https://www.namesilo.net</forward_url> <forward_type>Temporary Forward (302)</forward_type> <nameservers> <nameserver position="1">NS1.NAMESILO.COM</nameserver> <nameserver position="2">NS2.NAMESILO.COM</nameserver> </nameservers> <contact_ids> <registrant>444444</registrant> <administrative>555555</administrative> <technical>666666</technical> <billing>7777777</billing> </contact_ids> </reply> </namesilo>'; $xml_2 = '<namesilo><request><operation>checkRegisterAvailability</operation><ip>1.1.1.1</ip></request><reply><code>300</code><detail>success</detail><available><domain price="11.79" premium="0">nononononodneodneond.net</domain></available></reply></namesilo>'; $simple_test_1 = new simplexmlelement($xml_1); $simple_test_2 = new simplexmlelement($xml_2); function formatResponse($data, $assoc = false) { $data = json_decode(json_encode($data)); $data = formatAttributes($data); return json_decode(json_encode($data), $assoc); } function formatAttributes($attributes) { foreach ($attributes as $key => $attribute) { if (is_array($attribute)) { $attributes->{$key} = formatAttributes((object)$attribute); $attributes->{$key} = (array)$attributes->{$key}; } if (is_object($attribute)) { $attributes->{$key} = formatAttributes($attribute); if (isset($attribute->{'@attributes'})) { unset($attributes->{$key}->{'@attributes'}); } } if (!is_scalar($attributes->{$key})) { foreach ($attributes->{$key} as $a_key => $items) { if (!is_scalar($items)) { if (count((array) $items) == 1 && is_array($attributes->{$key})) { $attributes->{$key}[$a_key] = $items->{0}; } if (count((array) $items) == 1 && is_object($attributes->{$key})) { if (isset($items->{0})) { $attributes->{$key}->{$a_key} = $items->{0}; } } } } } } return $attributes; } print_r(formatResponse($simple_test_1)); print_r(formatResponse($simple_test_2));
based on inpUR
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nmfrc
function name:  (null)
number of ops:  23
compiled vars:  !0 = $xml_1, !1 = $xml_2, !2 = $simple_test_1, !3 = $simple_test_2
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   ASSIGN                                                   !0, '%3Cnamesilo%3E%0A++++%3Crequest%3E%0A++++++++%3Coperation%3EgetDomainInfo%3C%2Foperation%3E%0A++++++++%3Cip%3E55.555.55.55%3C%2Fip%3E%0A++++%3C%2Frequest%3E%0A++++%3Creply%3E%0A++++++++%3Ccode%3E300%3C%2Fcode%3E%0A++++++++%3Cdetail%3Esuccess%3C%2Fdetail%3E%0A++++++++%3Ccreated%3E2009-01-11%3C%2Fcreated%3E%0A++++++++%3Cexpires%3E2017-01-11%3C%2Fexpires%3E%0A++++++++%3Cstatus%3EActive%3C%2Fstatus%3E%0A++++++++%3Clocked%3EYes%3C%2Flocked%3E%0A++++++++%3Cprivate%3EYes%3C%2Fprivate%3E%0A++++++++%3Cauto_renew%3EYes%3C%2Fauto_renew%3E%0A++++++++%3Ctraffic_type%3EForwarded%3C%2Ftraffic_type%3E%0A++++++++%3Cemail_verification_required%3ENo%3C%2Femail_verification_required%3E%0A++++++++%3Cportfolio%3EMain+Portfolio%3C%2Fportfolio%3E%0A++++++++%3Cforward_url%3Ehttps%3A%2F%2Fwww.namesilo.net%3C%2Fforward_url%3E%0A++++++++%3Cforward_type%3ETemporary+Forward+%28302%29%3C%2Fforward_type%3E%0A++++++++%3Cnameservers%3E%0A++++++++++++%3Cnameserver+position%3D%221%22%3ENS1.NAMESILO.COM%3C%2Fnameserver%3E%0A++++++++++++%3Cnameserver+position%3D%222%22%3ENS2.NAMESILO.COM%3C%2Fnameserver%3E%0A++++++++%3C%2Fnameservers%3E%0A++++++++%3Ccontact_ids%3E%0A++++++++++++%3Cregistrant%3E444444%3C%2Fregistrant%3E%0A++++++++++++%3Cadministrative%3E555555%3C%2Fadministrative%3E%0A++++++++++++%3Ctechnical%3E666666%3C%2Ftechnical%3E%0A++++++++++++%3Cbilling%3E7777777%3C%2Fbilling%3E%0A++++++++%3C%2Fcontact_ids%3E%0A++++%3C%2Freply%3E%0A%3C%2Fnamesilo%3E'
  35     1        ASSIGN                                                   !1, '%3Cnamesilo%3E%3Crequest%3E%3Coperation%3EcheckRegisterAvailability%3C%2Foperation%3E%3Cip%3E1.1.1.1%3C%2Fip%3E%3C%2Frequest%3E%3Creply%3E%3Ccode%3E300%3C%2Fcode%3E%3Cdetail%3Esuccess%3C%2Fdetail%3E%3Cavailable%3E%3Cdomain+price%3D%2211.79%22+premium%3D%220%22%3Enononononodneodneond.net%3C%2Fdomain%3E%3C%2Favailable%3E%3C%2Freply%3E%3C%2Fnamesilo%3E'
  37     2        NEW                                              $6      :39
         3        SEND_VAR_EX                                              !0
         4        DO_FCALL                                      0          
         5        ASSIGN                                                   !2, $6
  38     6        NEW                                              $9      :33
         7        SEND_VAR_EX                                              !1
         8        DO_FCALL                                      0          
         9        ASSIGN                                                   !3, $9
  84    10        INIT_FCALL                                               'print_r'
        11        INIT_FCALL                                               'formatresponse'
        12        SEND_VAR                                                 !2
        13        DO_FCALL                                      0  $12     
        14        SEND_VAR                                                 $12
        15        DO_ICALL                                                 
  85    16        INIT_FCALL                                               'print_r'
        17        INIT_FCALL                                               'formatresponse'
        18        SEND_VAR                                                 !3
        19        DO_FCALL                                      0  $14     
        20        SEND_VAR                                                 $14
        21        DO_ICALL                                                 
        22      > RETURN                                                   1

Function formatresponse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Nmfrc
function name:  formatResponse
number of ops:  22
compiled vars:  !0 = $data, !1 = $assoc
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  40     0  E >   RECV                                             !0      
         1        RECV_INIT                                        !1      <false>
  42     2        INIT_FCALL                                               'json_decode'
         3        INIT_FCALL                                               'json_encode'
         4        SEND_VAR                                                 !0
         5        DO_ICALL                                         $2      
         6        SEND_VAR                                                 $2
         7        DO_ICALL                                         $3      
         8        ASSIGN                                                   !0, $3
  43     9        INIT_FCALL_BY_NAME                                       'formatAttributes'
        10        SEND_VAR_EX                                              !0
        11        DO_FCALL                                      0  $5      
        12        ASSIGN                                                   !0, $5
  45    13        INIT_FCALL                                               'json_decode'
        14        INIT_FCALL                                               'json_encode'
        15        SEND_VAR                                                 !0
        16        DO_ICALL                                         $7      
        17        SEND_VAR                                                 $7
        18        SEND_VAR                                                 !1
        19        DO_ICALL                                         $8      
        20      > RETURN                                                   $8
  46    21*     > RETURN                                                   null

End of function formatresponse

Function formatattributes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 71
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 71
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 27
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 70
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 69
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 69
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 68
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 54
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 58, Position 2 = 61
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 68
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 68
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 68
Branch analysis from position: 68
Branch analysis from position: 61
Branch analysis from position: 54
Branch analysis from position: 49
Branch analysis from position: 68
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 69
Branch analysis from position: 70
Branch analysis from position: 27
Branch analysis from position: 27
Branch analysis from position: 16
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
filename:       /in/Nmfrc
function name:  formatAttributes
number of ops:  74
compiled vars:  !0 = $attributes, !1 = $attribute, !2 = $key, !3 = $items, !4 = $a_key
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  48     0  E >   RECV                                             !0      
  50     1      > FE_RESET_R                                       $5      !0, ->71
         2    > > FE_FETCH_R                                       ~6      $5, !1, ->71
         3    >   ASSIGN                                                   !2, ~6
  51     4        TYPE_CHECK                                  128  ~8      !1
         5      > JMPZ                                                     ~8, ->16
  52     6    >   INIT_FCALL_BY_NAME                                       'formatAttributes'
         7        MAKE_REF                                         ~10     !1
         8        SEND_VAL_EX                                              ~10
         9        DO_FCALL                                      0  $11     
        10        ASSIGN_OBJ                                               !0, !2
        11        OP_DATA                                                  $11
  53    12        FETCH_OBJ_R                                      ~13     !0, !2
        13        MAKE_REF                                         ~14     ~13
        14        ASSIGN_OBJ                                               !0, !2
        15        OP_DATA                                                  ~14
  56    16    >   TYPE_CHECK                                  256  ~15     !1
        17      > JMPZ                                                     ~15, ->27
  57    18    >   INIT_FCALL_BY_NAME                                       'formatAttributes'
        19        SEND_VAR_EX                                              !1
        20        DO_FCALL                                      0  $17     
        21        ASSIGN_OBJ                                               !0, !2
        22        OP_DATA                                                  $17
  59    23        ISSET_ISEMPTY_PROP_OBJ                           ~18     !1, '%40attributes'
        24      > JMPZ                                                     ~18, ->27
  60    25    >   FETCH_OBJ_UNSET                                  $19     !0, !2
        26        UNSET_OBJ                                                $19, '%40attributes'
  64    27    >   INIT_FCALL                                               'is_scalar'
        28        FETCH_OBJ_R                                      ~20     !0, !2
        29        SEND_VAL                                                 ~20
        30        DO_ICALL                                         $21     
        31        BOOL_XOR                                         ~22     $21
        32      > JMPZ                                                     ~22, ->70
  65    33    >   FETCH_OBJ_R                                      ~23     !0, !2
        34      > FE_RESET_R                                       $24     ~23, ->69
        35    > > FE_FETCH_R                                       ~25     $24, !3, ->69
        36    >   ASSIGN                                                   !4, ~25
  66    37        INIT_FCALL                                               'is_scalar'
        38        SEND_VAR                                                 !3
        39        DO_ICALL                                         $27     
        40        BOOL_XOR                                         ~28     $27
        41      > JMPZ                                                     ~28, ->68
  67    42    >   MAKE_REF                                         ~29     !3
        43        COUNT                                            ~30     ~29
        44        IS_NOT_EQUAL                                     ~31     ~30, 1
        45      > JMPZ_EX                                          ~31     ~31, ->49
        46    >   FETCH_OBJ_R                                      ~32     !0, !2
        47        TYPE_CHECK                                  128  ~33     ~32
        48        BOOL                                             ~31     ~33
        49    > > JMPZ                                                     ~31, ->54
  68    50    >   FETCH_OBJ_R                                      ~36     !3, '0'
        51        FETCH_OBJ_W                                      $34     !0, !2
        52        ASSIGN_DIM                                               $34, !4
        53        OP_DATA                                                  ~36
  71    54    >   MAKE_REF                                         ~37     !3
        55        COUNT                                            ~38     ~37
        56        IS_NOT_EQUAL                                     ~39     ~38, 1
        57      > JMPZ_EX                                          ~39     ~39, ->61
        58    >   FETCH_OBJ_R                                      ~40     !0, !2
        59        TYPE_CHECK                                  256  ~41     ~40
        60        BOOL                                             ~39     ~41
        61    > > JMPZ                                                     ~39, ->68
  72    62    >   ISSET_ISEMPTY_PROP_OBJ                           ~42     !3, '0'
        63      > JMPZ                                                     ~42, ->68
  73    64    >   FETCH_OBJ_R                                      ~45     !3, '0'
        65        FETCH_OBJ_W                                      $43     !0, !2
        66        ASSIGN_OBJ                                               $43, !4
        67        OP_DATA                                                  ~45
  65    68    > > JMP                                                      ->35
        69    >   FE_FREE                                                  $24
  50    70    > > JMP                                                      ->2
        71    >   FE_FREE                                                  $5
  81    72      > RETURN                                                   !0
  82    73*     > RETURN                                                   null

End of function formatattributes

Generated using Vulcan Logic Dumper, using php 7.4.0