3v4l.org

run code in 300+ PHP versions simultaneously
<?php function process_xml(string $xml_string) : array { // Process XML $xml = simplexml_load_string($xml_string); // Return array $my_json['messages'] = []; // Iterate over nodes foreach($xml->children() as $message) { // Technically not needed $tmp = []; // Iterate over attributes foreach($message->attributes() as $name => $value) { $tmp[$name] = $value; } $my_json['messages'][] = $tmp; } return $my_json; } $xml_string_1 = <<<EOT <messages> <message message="asdf" franchise_id="0000" id="1661170418wng204" posted="Mon Aug 22 8:13:38 a.m. ET 2022"/> </messages> EOT; $xml_string_2 = <<<EOT <messages> <message franchise_id="0000" id="1661174329csw208" posted="Mon Aug 22 9:18:49 a.m. ET 2022" message="asdf"/> <message id="1661170418wng204" posted="Mon Aug 22 8:13:38 a.m. ET 2022" franchise_id="0000" message="asdf"/> </messages> EOT; echo json_encode(process_xml($xml_string_1)); echo PHP_EOL; echo json_encode(process_xml($xml_string_2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ifZcb
function name:  (null)
number of ops:  18
compiled vars:  !0 = $xml_string_1, !1 = $xml_string_2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, '%3Cmessages%3E%0A%3Cmessage+message%3D%22asdf%22+franchise_id%3D%220000%22+id%3D%221661170418wng204%22+posted%3D%22Mon+Aug+22+8%3A13%3A38+a.m.+ET+2022%22%2F%3E%0A%3C%2Fmessages%3E'
   33     1        ASSIGN                                                   !1, '%3Cmessages%3E%0A%3Cmessage+franchise_id%3D%220000%22+id%3D%221661174329csw208%22+posted%3D%22Mon+Aug+22+9%3A18%3A49+a.m.+ET+2022%22+message%3D%22asdf%22%2F%3E%0A%3Cmessage+id%3D%221661170418wng204%22+posted%3D%22Mon+Aug+22+8%3A13%3A38+a.m.+ET+2022%22+franchise_id%3D%220000%22+message%3D%22asdf%22%2F%3E%0A%3C%2Fmessages%3E'
   40     2        INIT_FCALL                                               'json_encode'
          3        INIT_FCALL                                               'process_xml'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                         $5      
          8        ECHO                                                     $5
   41     9        ECHO                                                     '%0A'
   42    10        INIT_FCALL                                               'json_encode'
         11        INIT_FCALL                                               'process_xml'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        ECHO                                                     $7
         17      > RETURN                                                   1

Function process_xml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 20
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/ifZcb
function name:  process_xml
number of ops:  30
compiled vars:  !0 = $xml_string, !1 = $xml, !2 = $my_json, !3 = $message, !4 = $tmp, !5 = $value, !6 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'simplexml_load_string'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
    9     5        ASSIGN_DIM                                               !2, 'messages'
          6        OP_DATA                                                  <array>
   12     7        INIT_METHOD_CALL                                         !1, 'children'
          8        DO_FCALL                                      0  $10     
          9      > FE_RESET_R                                       $11     $10, ->25
         10    > > FE_FETCH_R                                               $11, !3, ->25
   15    11    >   ASSIGN                                                   !4, <array>
   18    12        INIT_METHOD_CALL                                         !3, 'attributes'
         13        DO_FCALL                                      0  $13     
         14      > FE_RESET_R                                       $14     $13, ->20
         15    > > FE_FETCH_R                                       ~15     $14, !5, ->20
         16    >   ASSIGN                                                   !6, ~15
   19    17        ASSIGN_DIM                                               !4, !6
         18        OP_DATA                                                  !5
   18    19      > JMP                                                      ->15
         20    >   FE_FREE                                                  $14
   21    21        FETCH_DIM_W                                      $18     !2, 'messages'
         22        ASSIGN_DIM                                               $18
         23        OP_DATA                                                  !4
   12    24      > JMP                                                      ->10
         25    >   FE_FREE                                                  $11
   24    26        VERIFY_RETURN_TYPE                                       !2
         27      > RETURN                                                   !2
   25    28*       VERIFY_RETURN_TYPE                                       
         29*     > RETURN                                                   null

End of function process_xml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.6 ms | 1006 KiB | 17 Q