3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = <<<'XML' <XML> <Project Element1='some random value' Element2='Will be stored as attribute instead'/> </XML> XML; $document = new DOMDocument(); $document->loadXML($xml); $xpath = new DOMXpath($document); // iterate the first 'Project' element foreach($xpath->evaluate('(/XML/Project)[1]') as $project) { // change the attribute value $project->setAttribute('Element1', 'updated value'); } echo $document->saveXML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/md0qc
function name:  (null)
number of ops:  26
compiled vars:  !0 = $xml, !1 = $document, !2 = $xpath, !3 = $project
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3CXML%3E%0A+++%3CProject+Element1%3D%27some+random+value%27+Element2%3D%27Will+be+stored+as+attribute+instead%27%2F%3E%0A%3C%2FXML%3E'
    9     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   10     4        INIT_METHOD_CALL                                         !1, 'loadXML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   11     7        NEW                                              $9      'DOMXpath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $9
   14    11        INIT_METHOD_CALL                                         !2, 'evaluate'
         12        SEND_VAL_EX                                              '%28%2FXML%2FProject%29%5B1%5D'
         13        DO_FCALL                                      0  $12     
         14      > FE_RESET_R                                       $13     $12, ->21
         15    > > FE_FETCH_R                                               $13, !3, ->21
   16    16    >   INIT_METHOD_CALL                                         !3, 'setAttribute'
         17        SEND_VAL_EX                                              'Element1'
         18        SEND_VAL_EX                                              'updated+value'
         19        DO_FCALL                                      0          
   14    20      > JMP                                                      ->15
         21    >   FE_FREE                                                  $13
   19    22        INIT_METHOD_CALL                                         !1, 'saveXML'
         23        DO_FCALL                                      0  $15     
         24        ECHO                                                     $15
         25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.44 ms | 1003 KiB | 13 Q