3v4l.org

run code in 300+ PHP versions simultaneously
<?php // suppose some data is missing... $data = []; $data["height"]=""; $data['text']="more testing"; // get XML into a variable ... $xml = <<<XML <template> <height>$data[height]</height> <width>$data[height]</width> <text>$data[text]</text> </template> XML; $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->loadXML( $xml ); $template = $dom->getElementsByTagName('template')->item(0); $nodeList = $template->childNodes; echo (function() use($dom,$template,$nodeList){ // iterate backwards to remove node missing value for( $max=$nodeList->length-1, $i=0; $max >= $i; $max-- ) { $currNode = $nodeList->item($max); $status = $currNode->hasChildNodes()? true:false; if ($status === false) { $currNode->parentNode->removeChild( $currNode ); }// end if }// end for return $dom->saveXML( $template ); })(); // immediate executable
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j9nf9
function name:  (null)
number of ops:  41
compiled vars:  !0 = $data, !1 = $xml, !2 = $dom, !3 = $template, !4 = $nodeList
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN_DIM                                               !0, 'height'
          2        OP_DATA                                                  ''
    6     3        ASSIGN_DIM                                               !0, 'text'
          4        OP_DATA                                                  'more+testing'
   10     5        ROPE_INIT                                     7  ~12     '++++%3Ctemplate%3E%0A++++++++%3Cheight%3E'
   11     6        FETCH_DIM_R                                      ~8      !0, 'height'
          7        ROPE_ADD                                      1  ~12     ~12, ~8
          8        ROPE_ADD                                      2  ~12     ~12, '%3C%2Fheight%3E%0A++++++++%3Cwidth%3E'
   12     9        FETCH_DIM_R                                      ~9      !0, 'height'
         10        ROPE_ADD                                      3  ~12     ~12, ~9
         11        ROPE_ADD                                      4  ~12     ~12, '%3C%2Fwidth%3E%0A++++++++%3Ctext%3E'
   13    12        FETCH_DIM_R                                      ~10     !0, 'text'
         13        ROPE_ADD                                      5  ~12     ~12, ~10
         14        ROPE_END                                      6  ~11     ~12, '%3C%2Ftext%3E%0A++++%3C%2Ftemplate%3E'
    9    15        ASSIGN                                                   !1, ~11
   18    16        NEW                                              $17     'DOMDocument'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !2, $17
   19    19        ASSIGN_OBJ                                               !2, 'preserveWhiteSpace'
         20        OP_DATA                                                  <false>
   20    21        INIT_METHOD_CALL                                         !2, 'loadXML'
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0          
   21    24        INIT_METHOD_CALL                                         !2, 'getElementsByTagName'
         25        SEND_VAL_EX                                              'template'
         26        DO_FCALL                                      0  $22     
         27        INIT_METHOD_CALL                                         $22, 'item'
         28        SEND_VAL_EX                                              0
         29        DO_FCALL                                      0  $23     
         30        ASSIGN                                                   !3, $23
   22    31        FETCH_OBJ_R                                      ~25     !3, 'childNodes'
         32        ASSIGN                                                   !4, ~25
   24    33        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fj9nf9%3A24%240'
         34        BIND_LEXICAL                                             ~27, !2
         35        BIND_LEXICAL                                             ~27, !3
         36        BIND_LEXICAL                                             ~27, !4
   34    37        INIT_DYNAMIC_CALL                                        ~27
         38        DO_FCALL                                      0  $28     
         39        ECHO                                                     $28
         40      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fj9nf9%3A24%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 8
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 8
Branch analysis from position: 28
Branch analysis from position: 8
Branch analysis from position: 25
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
Branch analysis from position: 25
filename:       /in/j9nf9
function name:  {closure}
number of ops:  33
compiled vars:  !0 = $dom, !1 = $template, !2 = $nodeList, !3 = $max, !4 = $i, !5 = $currNode, !6 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   26     3        FETCH_OBJ_R                                      ~7      !2, 'length'
          4        SUB                                              ~8      ~7, 1
          5        ASSIGN                                                   !3, ~8
          6        ASSIGN                                                   !4, 0
          7      > JMP                                                      ->26
   27     8    >   INIT_METHOD_CALL                                         !2, 'item'
          9        SEND_VAR_EX                                              !3
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !5, $11
   28    12        INIT_METHOD_CALL                                         !5, 'hasChildNodes'
         13        DO_FCALL                                      0  $13     
         14      > JMPZ                                                     $13, ->17
         15    >   QM_ASSIGN                                        ~14     <true>
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~14     <false>
         18    >   ASSIGN                                                   !6, ~14
   29    19        TYPE_CHECK                                    4          !6
         20      > JMPZ                                                     ~16, ->25
   30    21    >   FETCH_OBJ_R                                      ~17     !5, 'parentNode'
         22        INIT_METHOD_CALL                                         ~17, 'removeChild'
         23        SEND_VAR_EX                                              !5
         24        DO_FCALL                                      0          
   26    25    >   PRE_DEC                                                  !3
         26    >   IS_SMALLER_OR_EQUAL                                      !4, !3
         27      > JMPNZ                                                    ~20, ->8
   33    28    >   INIT_METHOD_CALL                                         !0, 'saveXML'
         29        SEND_VAR_EX                                              !1
         30        DO_FCALL                                      0  $21     
         31      > RETURN                                                   $21
   34    32*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fj9nf9%3A24%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.03 ms | 1403 KiB | 13 Q