3v4l.org

run code in 300+ 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));
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      'simplexmlelement'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $6
   38     6        NEW                                              $9      'simplexmlelement'
          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 = 67
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 67
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 = 31, Position 2 = 66
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 65
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 65
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 64
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 64
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 64
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 64
Branch analysis from position: 64
Branch analysis from position: 57
Branch analysis from position: 50
Branch analysis from position: 45
Branch analysis from position: 64
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 65
Branch analysis from position: 66
Branch analysis from position: 27
Branch analysis from position: 27
Branch analysis from position: 16
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
filename:       /in/Nmfrc
function name:  formatAttributes
number of ops:  70
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, ->67
          2    > > FE_FETCH_R                                       ~6      $5, !1, ->67
          3    >   ASSIGN                                                   !2, ~6
   51     4        TYPE_CHECK                                  128          !1
          5      > JMPZ                                                     ~8, ->16
   52     6    >   INIT_FCALL_BY_NAME                                       'formatAttributes'
          7        CAST                                          8  ~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        CAST                                          7  ~14     ~13
         14        ASSIGN_OBJ                                               !0, !2
         15        OP_DATA                                                  ~14
   56    16    >   TYPE_CHECK                                  256          !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                                   !1, '%40attributes'
         24      > JMPZ                                                     ~18, ->27
   60    25    >   FETCH_OBJ_UNSET                                  $19     !0, !2
         26        UNSET_OBJ                                                $19, '%40attributes'
   64    27    >   FETCH_OBJ_R                                      ~20     !0, !2
         28        TYPE_CHECK                                  124  ~21     ~20
         29        BOOL_NOT                                         ~22     ~21
         30      > JMPZ                                                     ~22, ->66
   65    31    >   FETCH_OBJ_R                                      ~23     !0, !2
         32      > FE_RESET_R                                       $24     ~23, ->65
         33    > > FE_FETCH_R                                       ~25     $24, !3, ->65
         34    >   ASSIGN                                                   !4, ~25
   66    35        TYPE_CHECK                                  124  ~27     !3
         36        BOOL_NOT                                         ~28     ~27
         37      > JMPZ                                                     ~28, ->64
   67    38    >   CAST                                          7  ~29     !3
         39        COUNT                                            ~30     ~29
         40        IS_EQUAL                                         ~31     ~30, 1
         41      > JMPZ_EX                                          ~31     ~31, ->45
         42    >   FETCH_OBJ_R                                      ~32     !0, !2
         43        TYPE_CHECK                                  128  ~33     ~32
         44        BOOL                                             ~31     ~33
         45    > > JMPZ                                                     ~31, ->50
   68    46    >   FETCH_OBJ_R                                      ~36     !3, '0'
         47        FETCH_OBJ_W                                      $34     !0, !2
         48        ASSIGN_DIM                                               $34, !4
         49        OP_DATA                                                  ~36
   71    50    >   CAST                                          7  ~37     !3
         51        COUNT                                            ~38     ~37
         52        IS_EQUAL                                         ~39     ~38, 1
         53      > JMPZ_EX                                          ~39     ~39, ->57
         54    >   FETCH_OBJ_R                                      ~40     !0, !2
         55        TYPE_CHECK                                  256  ~41     ~40
         56        BOOL                                             ~39     ~41
         57    > > JMPZ                                                     ~39, ->64
   72    58    >   ISSET_ISEMPTY_PROP_OBJ                                   !3, '0'
         59      > JMPZ                                                     ~42, ->64
   73    60    >   FETCH_OBJ_R                                      ~45     !3, '0'
         61        FETCH_OBJ_W                                      $43     !0, !2
         62        ASSIGN_OBJ                                               $43, !4
         63        OP_DATA                                                  ~45
   65    64    > > JMP                                                      ->33
         65    >   FE_FREE                                                  $24
   50    66    > > JMP                                                      ->2
         67    >   FE_FREE                                                  $5
   81    68      > RETURN                                                   !0
   82    69*     > RETURN                                                   null

End of function formatattributes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.31 ms | 1411 KiB | 21 Q