3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo LIBXML_DOTTED_VERSION, "\n"; $xml = <<<'XML' <products> <product category="Desktop"> <name> Desktop 1 (d)</name> <price>499.99</price> </product> <product category="Tablet"> <name>Tablet 1 (t)</name> <price>1099.99</price> </product> </products> XML; $reader = new XMLReader; $reader->open('data://text/xml,'.$xml); $dom = new DOMDocument; $xpath = new DOMXpath($dom); // look for the first product element while ($reader->read() && $reader->localName !== 'product') { continue; } // while you have an product element while ($reader->localName === 'product') { $node = $reader->expand($dom); var_dump( $xpath->evaluate('string(@category)', $node), $xpath->evaluate('string(name)', $node), $xpath->evaluate('number(price)', $node) ); // move to the next product sibling $reader->next('product'); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 18
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 27
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 27
Branch analysis from position: 54
Branch analysis from position: 27
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 25
filename:       /in/ol4uo
function name:  (null)
number of ops:  55
compiled vars:  !0 = $xml, !1 = $reader, !2 = $dom, !3 = $xpath, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ECHO                                                     '2.9.4'
          1        ECHO                                                     '%0A'
    4     2        ASSIGN                                                   !0, '%3Cproducts%3E%0A%0A%3Cproduct+category%3D%22Desktop%22%3E%0A%3Cname%3E+Desktop+1+%28d%29%3C%2Fname%3E%0A%3Cprice%3E499.99%3C%2Fprice%3E%0A%3C%2Fproduct%3E%0A%0A%3Cproduct+category%3D%22Tablet%22%3E%0A%3Cname%3ETablet+1+%28t%29%3C%2Fname%3E%0A%3Cprice%3E1099.99%3C%2Fprice%3E%0A%3C%2Fproduct%3E%0A%0A%3C%2Fproducts%3E'
   20     3        NEW                                              $6      'XMLReader'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   21     6        INIT_METHOD_CALL                                         !1, 'open'
          7        CONCAT                                           ~9      'data%3A%2F%2Ftext%2Fxml%2C', !0
          8        SEND_VAL_EX                                              ~9
          9        DO_FCALL                                      0          
   22    10        NEW                                              $11     'DOMDocument'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $11
   23    13        NEW                                              $14     'DOMXpath'
         14        SEND_VAR_EX                                              !2
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !3, $14
   26    17      > JMP                                                      ->19
   27    18    > > JMP                                                      ->19
   26    19    >   INIT_METHOD_CALL                                         !1, 'read'
         20        DO_FCALL                                      0  $17     
         21      > JMPZ_EX                                          ~18     $17, ->25
         22    >   FETCH_OBJ_R                                      ~19     !1, 'localName'
         23        IS_NOT_IDENTICAL                                 ~20     ~19, 'product'
         24        BOOL                                             ~18     ~20
         25    > > JMPNZ                                                    ~18, ->18
   31    26    > > JMP                                                      ->51
   32    27    >   INIT_METHOD_CALL                                         !1, 'expand'
         28        SEND_VAR_EX                                              !2
         29        DO_FCALL                                      0  $21     
         30        ASSIGN                                                   !4, $21
   33    31        INIT_FCALL                                               'var_dump'
   34    32        INIT_METHOD_CALL                                         !3, 'evaluate'
         33        SEND_VAL_EX                                              'string%28%40category%29'
         34        SEND_VAR_EX                                              !4
         35        DO_FCALL                                      0  $23     
         36        SEND_VAR                                                 $23
   35    37        INIT_METHOD_CALL                                         !3, 'evaluate'
         38        SEND_VAL_EX                                              'string%28name%29'
         39        SEND_VAR_EX                                              !4
         40        DO_FCALL                                      0  $24     
         41        SEND_VAR                                                 $24
   36    42        INIT_METHOD_CALL                                         !3, 'evaluate'
         43        SEND_VAL_EX                                              'number%28price%29'
         44        SEND_VAR_EX                                              !4
         45        DO_FCALL                                      0  $25     
         46        SEND_VAR                                                 $25
         47        DO_ICALL                                                 
   39    48        INIT_METHOD_CALL                                         !1, 'next'
         49        SEND_VAL_EX                                              'product'
         50        DO_FCALL                                      0          
   31    51    >   FETCH_OBJ_R                                      ~28     !1, 'localName'
         52        IS_IDENTICAL                                             ~28, 'product'
         53      > JMPNZ                                                    ~29, ->27
   40    54    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.11 ms | 1400 KiB | 15 Q