3v4l.org

run code in 500+ PHP versions simultaneously
<?php $doc = new DOMDocument(); $doc->loadXML( <<<XML <container xmlns="http://symfony.com/schema/dic/services"> CHILDREN </container> XML ); // // Remove xmlns Attribute + Validate it is actually gone. // As you can see, it still remembers a 'xmlns' DOMNameSpaceNode with an empty namespaceURI (which basically is invalid!) // $doc->documentElement->removeAttributeNS('http://symfony.com/schema/dic/services', ''); var_dump($doc->documentElement->getAttributeNode('xmlns')); $namespaces = [...(new DOMXPath($doc))->query('./namespace::*', $doc->documentElement)]; // // Yet when saving the XML : there is no problem, the namespaces are gone. // echo $doc->saveXML(); var_dump($namespaces); // // However ... // When importing the node in a new document, it gets prefixed by <default:container ...> without any xmlns:default declaration // $new = new DOMDocument(); $new->append( $new->importNode($doc->documentElement, true) ); echo $new->saveXML(); // Resulting in invalid XML obviously: $previousErrorReporting = libxml_use_internal_errors(true); libxml_clear_errors(); $parsedAgain = new DOMDocument(); $parsedAgain->loadXML($new->saveXML()); $errors = libxml_get_errors(); libxml_clear_errors(); libxml_use_internal_errors($previousErrorReporting); var_dump($errors);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOrNb
function name:  (null)
number of ops:  77
compiled vars:  !0 = $doc, !1 = $namespaces, !2 = $new, !3 = $previousErrorReporting, !4 = $parsedAgain, !5 = $errors
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   NEW                                                  $6      'DOMDocument'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $6
    4     3        INIT_METHOD_CALL                                             !0, 'loadXML'
    6     4        SEND_VAL_EX                                                  '%3Ccontainer+xmlns%3D%22http%3A%2F%2Fsymfony.com%2Fschema%2Fdic%2Fservices%22%3E%0A++CHILDREN%0A%3C%2Fcontainer%3E'
    4     5        DO_FCALL                                          0          
   16     6        FETCH_OBJ_R                                          ~10     !0, 'documentElement'
          7        INIT_METHOD_CALL                                             ~10, 'removeAttributeNS'
          8        SEND_VAL_EX                                                  'http%3A%2F%2Fsymfony.com%2Fschema%2Fdic%2Fservices'
          9        SEND_VAL_EX                                                  ''
         10        DO_FCALL                                          0          
   17    11        INIT_FCALL                                                   'var_dump'
         12        FETCH_OBJ_R                                          ~12     !0, 'documentElement'
         13        INIT_METHOD_CALL                                             ~12, 'getAttributeNode'
         14        SEND_VAL_EX                                                  'xmlns'
         15        DO_FCALL                                          0  $13     
         16        SEND_VAR                                                     $13
         17        DO_ICALL                                                     
   18    18        NEW                                                  $15     'DOMXPath'
         19        SEND_VAR_EX                                                  !0
         20        DO_FCALL                                          0          
         21        INIT_METHOD_CALL                                             $15, 'query'
         22        SEND_VAL_EX                                                  '.%2Fnamespace%3A%3A%2A'
         23        CHECK_FUNC_ARG                                               
         24        FETCH_OBJ_FUNC_ARG                                   $17     !0, 'documentElement'
         25        SEND_FUNC_ARG                                                $17
         26        DO_FCALL                                          0  $18     
         27        INIT_ARRAY                                           ~19     
         28        ADD_ARRAY_UNPACK                                     ~19     $18
         29        ASSIGN                                                       !1, ~19
   23    30        INIT_METHOD_CALL                                             !0, 'saveXML'
         31        DO_FCALL                                          0  $21     
         32        ECHO                                                         $21
   24    33        INIT_FCALL                                                   'var_dump'
         34        SEND_VAR                                                     !1
         35        DO_ICALL                                                     
   32    36        NEW                                                  $23     'DOMDocument'
         37        DO_FCALL                                          0          
         38        ASSIGN                                                       !2, $23
   33    39        INIT_METHOD_CALL                                             !2, 'append'
   34    40        INIT_METHOD_CALL                                             !2, 'importNode'
         41        CHECK_FUNC_ARG                                               
         42        FETCH_OBJ_FUNC_ARG                                   $26     !0, 'documentElement'
         43        SEND_FUNC_ARG                                                $26
         44        SEND_VAL_EX                                                  <true>
         45        DO_FCALL                                          0  $27     
         46        SEND_VAR_NO_REF_EX                                           $27
   33    47        DO_FCALL                                          0          
   37    48        INIT_METHOD_CALL                                             !2, 'saveXML'
         49        DO_FCALL                                          0  $29     
         50        ECHO                                                         $29
   40    51        INIT_FCALL                                                   'libxml_use_internal_errors'
         52        SEND_VAL                                                     <true>
         53        DO_ICALL                                             $30     
         54        ASSIGN                                                       !3, $30
   41    55        INIT_FCALL                                                   'libxml_clear_errors'
         56        DO_ICALL                                                     
   43    57        NEW                                                  $33     'DOMDocument'
         58        DO_FCALL                                          0          
         59        ASSIGN                                                       !4, $33
   44    60        INIT_METHOD_CALL                                             !4, 'loadXML'
         61        INIT_METHOD_CALL                                             !2, 'saveXML'
         62        DO_FCALL                                          0  $36     
         63        SEND_VAR_NO_REF_EX                                           $36
         64        DO_FCALL                                          0          
   45    65        INIT_FCALL                                                   'libxml_get_errors'
         66        DO_ICALL                                             $38     
         67        ASSIGN                                                       !5, $38
   47    68        INIT_FCALL                                                   'libxml_clear_errors'
         69        DO_ICALL                                                     
   48    70        INIT_FCALL                                                   'libxml_use_internal_errors'
         71        SEND_VAR                                                     !3
         72        DO_ICALL                                                     
   50    73        INIT_FCALL                                                   'var_dump'
         74        SEND_VAR                                                     !5
         75        DO_ICALL                                                     
         76      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
128.17 ms | 486 KiB | 11 Q