3v4l.org

run code in 300+ PHP versions simultaneously
<?php $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 = 17
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 25
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 25
Branch analysis from position: 52
Branch analysis from position: 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
filename:       /in/68Vep
function name:  (null)
number of ops:  53
compiled vars:  !0 = $xml, !1 = $reader, !2 = $dom, !3 = $xpath, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   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'
   19     1        NEW                                              $6      'XMLReader'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   20     4        INIT_METHOD_CALL                                         !1, 'open'
          5        CONCAT                                           ~9      'data%3A%2F%2Ftext%2Fxml%2C', !0
          6        SEND_VAL_EX                                              ~9
          7        DO_FCALL                                      0          
   21     8        NEW                                              $11     'DOMDocument'
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $11
   22    11        NEW                                              $14     'DOMXpath'
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !3, $14
   25    15      > JMP                                                      ->17
   26    16    > > JMP                                                      ->17
   25    17    >   INIT_METHOD_CALL                                         !1, 'read'
         18        DO_FCALL                                      0  $17     
         19      > JMPZ_EX                                          ~18     $17, ->23
         20    >   FETCH_OBJ_R                                      ~19     !1, 'localName'
         21        IS_NOT_IDENTICAL                                 ~20     ~19, 'product'
         22        BOOL                                             ~18     ~20
         23    > > JMPNZ                                                    ~18, ->16
   30    24    > > JMP                                                      ->49
   31    25    >   INIT_METHOD_CALL                                         !1, 'expand'
         26        SEND_VAR_EX                                              !2
         27        DO_FCALL                                      0  $21     
         28        ASSIGN                                                   !4, $21
   32    29        INIT_FCALL                                               'var_dump'
   33    30        INIT_METHOD_CALL                                         !3, 'evaluate'
         31        SEND_VAL_EX                                              'string%28%40category%29'
         32        SEND_VAR_EX                                              !4
         33        DO_FCALL                                      0  $23     
         34        SEND_VAR                                                 $23
   34    35        INIT_METHOD_CALL                                         !3, 'evaluate'
         36        SEND_VAL_EX                                              'string%28name%29'
         37        SEND_VAR_EX                                              !4
         38        DO_FCALL                                      0  $24     
         39        SEND_VAR                                                 $24
   35    40        INIT_METHOD_CALL                                         !3, 'evaluate'
         41        SEND_VAL_EX                                              'number%28price%29'
         42        SEND_VAR_EX                                              !4
         43        DO_FCALL                                      0  $25     
         44        SEND_VAR                                                 $25
         45        DO_ICALL                                                 
   38    46        INIT_METHOD_CALL                                         !1, 'next'
         47        SEND_VAL_EX                                              'product'
         48        DO_FCALL                                      0          
   30    49    >   FETCH_OBJ_R                                      ~28     !1, 'localName'
         50        IS_IDENTICAL                                             ~28, 'product'
         51      > JMPNZ                                                    ~29, ->25
   39    52    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.28 ms | 1400 KiB | 15 Q