3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlns = 'urn:foo'; $dom = new DOMDocument(); /* On the root level the prefix is replaced by default and the namespace for the attribute is lost */ $root = $dom->createElementNS($xmlns, 'element'); $root->setAttributeNS($xmlns, 'foo:attribute', 'bar'); $dom->appendChild($root); /* On the second level the prefix is replaced, the namespace declaration is duplicated and the element gets a prefix that was never provided. */ $child = $dom->createElementNS($xmlns, 'element'); $child->setAttributeNS($xmlns, 'foo:attribute', 'bar'); $root->appendChild($child); /* On the third level the prefix is replaced and the element gets a prefix again. */ $subchild = $dom->createElementNS($xmlns, 'element'); $subchild->setAttributeNS($xmlns, 'foo:attribute', 'bar'); $child->appendChild($subchild); /* If you add the element node before setting the attribute it gets no prefix */ $child = $dom->createElementNS($xmlns, 'element'); $root->appendChild($child); $child->setAttributeNS($xmlns, 'foo:attribute', 'bar'); $dom->formatOutput = TRUE; echo $dom->saveXml(); /* Expected <?xml version="1.0"?> <element xmlns="urn:foo" xmlns:foo="urn:foo" foo:attribute="bar"> <element foo:attribute="bar"> <element foo:attribute="bar"/> </element> <element foo:attribute="bar"/> </element> */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kreis
function name:  (null)
number of ops:  62
compiled vars:  !0 = $xmlns, !1 = $dom, !2 = $root, !3 = $child, !4 = $subchild
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'urn%3Afoo'
    5     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   11     4        INIT_METHOD_CALL                                         !1, 'createElementNS'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              'element'
          7        DO_FCALL                                      0  $9      
          8        ASSIGN                                                   !2, $9
   12     9        INIT_METHOD_CALL                                         !2, 'setAttributeNS'
         10        SEND_VAR_EX                                              !0
         11        SEND_VAL_EX                                              'foo%3Aattribute'
         12        SEND_VAL_EX                                              'bar'
         13        DO_FCALL                                      0          
   13    14        INIT_METHOD_CALL                                         !1, 'appendChild'
         15        SEND_VAR_EX                                              !2
         16        DO_FCALL                                      0          
   20    17        INIT_METHOD_CALL                                         !1, 'createElementNS'
         18        SEND_VAR_EX                                              !0
         19        SEND_VAL_EX                                              'element'
         20        DO_FCALL                                      0  $13     
         21        ASSIGN                                                   !3, $13
   21    22        INIT_METHOD_CALL                                         !3, 'setAttributeNS'
         23        SEND_VAR_EX                                              !0
         24        SEND_VAL_EX                                              'foo%3Aattribute'
         25        SEND_VAL_EX                                              'bar'
         26        DO_FCALL                                      0          
   22    27        INIT_METHOD_CALL                                         !2, 'appendChild'
         28        SEND_VAR_EX                                              !3
         29        DO_FCALL                                      0          
   28    30        INIT_METHOD_CALL                                         !1, 'createElementNS'
         31        SEND_VAR_EX                                              !0
         32        SEND_VAL_EX                                              'element'
         33        DO_FCALL                                      0  $17     
         34        ASSIGN                                                   !4, $17
   29    35        INIT_METHOD_CALL                                         !4, 'setAttributeNS'
         36        SEND_VAR_EX                                              !0
         37        SEND_VAL_EX                                              'foo%3Aattribute'
         38        SEND_VAL_EX                                              'bar'
         39        DO_FCALL                                      0          
   30    40        INIT_METHOD_CALL                                         !3, 'appendChild'
         41        SEND_VAR_EX                                              !4
         42        DO_FCALL                                      0          
   37    43        INIT_METHOD_CALL                                         !1, 'createElementNS'
         44        SEND_VAR_EX                                              !0
         45        SEND_VAL_EX                                              'element'
         46        DO_FCALL                                      0  $21     
         47        ASSIGN                                                   !3, $21
   38    48        INIT_METHOD_CALL                                         !2, 'appendChild'
         49        SEND_VAR_EX                                              !3
         50        DO_FCALL                                      0          
   39    51        INIT_METHOD_CALL                                         !3, 'setAttributeNS'
         52        SEND_VAR_EX                                              !0
         53        SEND_VAL_EX                                              'foo%3Aattribute'
         54        SEND_VAL_EX                                              'bar'
         55        DO_FCALL                                      0          
   41    56        ASSIGN_OBJ                                               !1, 'formatOutput'
         57        OP_DATA                                                  <true>
   42    58        INIT_METHOD_CALL                                         !1, 'saveXml'
         59        DO_FCALL                                      0  $26     
         60        ECHO                                                     $26
   53    61      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
281.78 ms | 1399 KiB | 14 Q