3v4l.org

run code in 300+ PHP versions simultaneously
<?php $template = <<<XML <?xml version="1.0" encoding="utf-8"?> <resources></resources> XML; $writer = new SimpleXMLElement( $template ); $messages = array( 'key' => 'value', 'anotherkey' => 'anothervalue', ); foreach ( $messages as $key => $value ) { $element = $writer->addChild( 'string', $value ); $element->addAttribute( 'name', $key ); // This is non-standard if ( $key === 'key' ) { $element->addAttribute( 'fuzzy', 'true' ); } } // Make the output pretty with DOMDocument $dom = new DOMDocument( '1.0' ); $dom->formatOutput = false; $dom->preserveWhiteSpace = true; $dom->loadXML( $writer->asXML() ); echo $dom->saveXML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/vC9IZ
function name:  (null)
number of ops:  43
compiled vars:  !0 = $template, !1 = $writer, !2 = $messages, !3 = $value, !4 = $key, !5 = $element, !6 = $dom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3Cresources%3E%3C%2Fresources%3E'
    8     1        NEW                                              $8      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $8
   10     5        ASSIGN                                                   !2, <array>
   15     6      > FE_RESET_R                                       $12     !2, ->25
          7    > > FE_FETCH_R                                       ~13     $12, !3, ->25
          8    >   ASSIGN                                                   !4, ~13
   16     9        INIT_METHOD_CALL                                         !1, 'addChild'
         10        SEND_VAL_EX                                              'string'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $15     
         13        ASSIGN                                                   !5, $15
   18    14        INIT_METHOD_CALL                                         !5, 'addAttribute'
         15        SEND_VAL_EX                                              'name'
         16        SEND_VAR_EX                                              !4
         17        DO_FCALL                                      0          
   20    18        IS_IDENTICAL                                             !4, 'key'
         19      > JMPZ                                                     ~18, ->24
   21    20    >   INIT_METHOD_CALL                                         !5, 'addAttribute'
         21        SEND_VAL_EX                                              'fuzzy'
         22        SEND_VAL_EX                                              'true'
         23        DO_FCALL                                      0          
   15    24    > > JMP                                                      ->7
         25    >   FE_FREE                                                  $12
   26    26        NEW                                              $20     'DOMDocument'
         27        SEND_VAL_EX                                              '1.0'
         28        DO_FCALL                                      0          
         29        ASSIGN                                                   !6, $20
   27    30        ASSIGN_OBJ                                               !6, 'formatOutput'
         31        OP_DATA                                                  <false>
   28    32        ASSIGN_OBJ                                               !6, 'preserveWhiteSpace'
         33        OP_DATA                                                  <true>
   29    34        INIT_METHOD_CALL                                         !6, 'loadXML'
         35        INIT_METHOD_CALL                                         !1, 'asXML'
         36        DO_FCALL                                      0  $25     
         37        SEND_VAR_NO_REF_EX                                       $25
         38        DO_FCALL                                      0          
   31    39        INIT_METHOD_CALL                                         !6, 'saveXML'
         40        DO_FCALL                                      0  $27     
         41        ECHO                                                     $27
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.44 ms | 1399 KiB | 13 Q