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 ? '' : $this->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/Kio8P
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 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 3
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 51
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 64
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 64
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 3
Branch analysis from position: 71
Branch analysis from position: 3
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 64
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kio8P
function name:  fromXML
number of ops:  73
compiled vars:  !0 = $xml, !1 = $node, !2 = $xmlErrors, !3 = $errorLines, !4 = $error
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2      > JMP                                                      ->68
    7     3    >   INIT_METHOD_CALL                                         !0, 'isValid'
          4        DO_FCALL                                      0  $6      
          5        BOOL_NOT                                         ~7      $6
          6      > JMPZ                                                     ~7, ->33
    8     7    >   INIT_FCALL                                               'libxml_get_errors'
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !2, $8
    9    10        ASSIGN                                                   !3, <array>
   10    11      > FE_RESET_R                                       $11     !2, ->24
         12    > > FE_FETCH_R                                               $11, !4, ->24
   11    13    >   FETCH_OBJ_R                                      ~13     !4, 'line'
         14        CONCAT                                           ~14     'Line%3A+', ~13
         15        CONCAT                                           ~15     ~14, '+Column%3A+'
         16        FETCH_OBJ_R                                      ~16     !4, 'column'
         17        CONCAT                                           ~17     ~15, ~16
         18        CONCAT                                           ~18     ~17, '+-+'
         19        FETCH_OBJ_R                                      ~19     !4, 'message'
         20        CONCAT                                           ~20     ~18, ~19
         21        ASSIGN_DIM                                               !3
         22        OP_DATA                                                  ~20
   10    23      > JMP                                                      ->12
         24    >   FE_FREE                                                  $11
   13    25        NEW                                              $21     'Exception'
         26        INIT_FCALL                                               'join'
         27        SEND_VAL                                                 ''
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $22     
         30        SEND_VAR_NO_REF_EX                                       $22
         31        DO_FCALL                                      0          
         32      > THROW                                         0          $21
   15    33    >   FETCH_OBJ_R                                      ~24     !0, 'nodeType'
         34        CASE                                                     ~24, 15
         35      > JMPNZ                                                    ~25, ->43
         36    >   CASE                                                     ~24, 1
         37      > JMPNZ                                                    ~25, ->51
         38    >   CASE                                                     ~24, 3
         39      > JMPNZ                                                    ~25, ->64
         40    >   CASE                                                     ~24, 4
         41      > JMPNZ                                                    ~25, ->64
         42    > > JMP                                                      ->67
   17    43    >   COUNT                                            ~26     !1
         44        IS_SMALLER                                               0, ~26
         45      > JMPZ                                                     ~27, ->48
         46    >   QM_ASSIGN                                        ~28     !1
         47      > JMP                                                      ->49
         48    >   QM_ASSIGN                                        ~28     null
         49    >   FREE                                                     ~24
         50      > RETURN                                                   ~28
   19    51    >   FETCH_OBJ_R                                      ~29     !0, 'name'
         52        FETCH_OBJ_R                                      ~31     !0, 'isEmptyElement'
         53      > JMPZ                                                     ~31, ->56
         54    >   QM_ASSIGN                                        ~32     ''
         55      > JMP                                                      ->61
         56    >   FETCH_THIS                                       $33     
         57        INIT_METHOD_CALL                                         $33, 'fromXML'
         58        SEND_VAR_EX                                              !0
         59        DO_FCALL                                      0  $34     
         60        QM_ASSIGN                                        ~32     $34
         61    >   ASSIGN_DIM                                               !1, ~29
         62        OP_DATA                                                  ~32
   20    63      > JMP                                                      ->67
   23    64    >   FETCH_OBJ_R                                      ~35     !0, 'value'
         65        ASSIGN                                                   !1, ~35
   24    66      > JMP                                                      ->67
         67    >   FREE                                                     ~24
    6    68    >   INIT_METHOD_CALL                                         !0, 'read'
         69        DO_FCALL                                      0  $37     
         70      > JMPNZ                                                    $37, ->3
   27    71    > > RETURN                                                   !1
   28    72*     > RETURN                                                   null

End of function fromxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.53 ms | 1407 KiB | 20 Q