3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fromXML(XMLReader $xml) { $node = []; while ($xml->read()) { // if (!$xml->isValid()) { // $xmlErrors = libxml_get_errors(); // $errorLines = array(); // foreach ($xmlErrors as $error) { // $errorLines[] = 'Line: ' . $error->line . ' Column: ' . $error->column . ' - ' . $error->message; // } // throw new Exception(join("", $errorLines)); // } switch ($xml->nodeType) { case XMLReader::END_ELEMENT: return (count($node) > 0) ? $node : null; case XMLReader::ELEMENT: $node[$xml->name] = ($xml->isEmptyElement ? '' : fromXML($xml)); break; case XMLReader::TEXT: case XMLReader::CDATA: $node = $xml->value; break; } } return $node; } $data = '<?xml version="1.0" encoding="UTF-8"?> <request> <header> <version>0.6</version> <dateTime>2017-07-05T11:21:46</dateTime> <sender>PROVIDER</sender> <recipient>dfsafdaf</recipient> <messageType>isvalid</messageType> </header> <voucher> <voucherId>1</voucherId> </voucher> </request>'; $xml = new XMLReader(); $xml->xml($data); var_dump(fromXML($xml));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0fd43
function name:  (null)
number of ops:  14
compiled vars:  !0 = $data, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A++++++++++++%3Crequest%3E%0A++++++++++++%3Cheader%3E%0A++++++++++++%3Cversion%3E0.6%3C%2Fversion%3E%0A++++++++++++%3CdateTime%3E2017-07-05T11%3A21%3A46%3C%2FdateTime%3E%0A++++++++++++%3Csender%3EPROVIDER%3C%2Fsender%3E%0A++++++++++++%3Crecipient%3Edfsafdaf%3C%2Frecipient%3E%0A++++++++++++%3CmessageType%3Eisvalid%3C%2FmessageType%3E%0A++++++++++++%3C%2Fheader%3E%0A++++++++++++%3Cvoucher%3E%0A++++++++++++%3CvoucherId%3E1%3C%2FvoucherId%3E%0A++++++++++++%3C%2Fvoucher%3E%0A++++++++++++%3C%2Frequest%3E'
   44     1        NEW                                              $3      'XMLReader'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $3
   45     4        INIT_METHOD_CALL                                         !1, 'xml'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   47     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'fromxml'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $7      
         11        SEND_VAR                                                 $7
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function fromxml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 3
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 33
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 3
Branch analysis from position: 40
Branch analysis from position: 3
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 33
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0fd43
function name:  fromXML
number of ops:  42
compiled vars:  !0 = $xml, !1 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2      > JMP                                                      ->37
   15     3    >   FETCH_OBJ_R                                      ~3      !0, 'nodeType'
          4        CASE                                                     ~3, 15
          5      > JMPNZ                                                    ~4, ->13
          6    >   CASE                                                     ~3, 1
          7      > JMPNZ                                                    ~4, ->21
          8    >   CASE                                                     ~3, 3
          9      > JMPNZ                                                    ~4, ->33
         10    >   CASE                                                     ~3, 4
         11      > JMPNZ                                                    ~4, ->33
         12    > > JMP                                                      ->36
   17    13    >   COUNT                                            ~5      !1
         14        IS_SMALLER                                               0, ~5
         15      > JMPZ                                                     ~6, ->18
         16    >   QM_ASSIGN                                        ~7      !1
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~7      null
         19    >   FREE                                                     ~3
         20      > RETURN                                                   ~7
   19    21    >   FETCH_OBJ_R                                      ~8      !0, 'name'
         22        FETCH_OBJ_R                                      ~10     !0, 'isEmptyElement'
         23      > JMPZ                                                     ~10, ->26
         24    >   QM_ASSIGN                                        ~11     ''
         25      > JMP                                                      ->30
         26    >   INIT_FCALL_BY_NAME                                       'fromXML'
         27        SEND_VAR_EX                                              !0
         28        DO_FCALL                                      0  $12     
         29        QM_ASSIGN                                        ~11     $12
         30    >   ASSIGN_DIM                                               !1, ~8
         31        OP_DATA                                                  ~11
   20    32      > JMP                                                      ->36
   23    33    >   FETCH_OBJ_R                                      ~13     !0, 'value'
         34        ASSIGN                                                   !1, ~13
   24    35      > JMP                                                      ->36
         36    >   FREE                                                     ~3
    6    37    >   INIT_METHOD_CALL                                         !0, 'read'
         38        DO_FCALL                                      0  $15     
         39      > JMPNZ                                                    $15, ->3
   27    40    > > RETURN                                                   !1
   28    41*     > RETURN                                                   null

End of function fromxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.05 ms | 1403 KiB | 16 Q