3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = <<<'HTML' <p> <span> <strong> <span> Test </span> </strong> </span> </p> HTML; $doc = new \DOMDocument('1.0', 'UTF-8'); $doc->loadHTML( '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $html . '</body></html>' ); $xpath = new \DOMXPath($doc); $spans = []; foreach ($xpath->query('//span') as $span) { $spans[] = $span; } \assert(\count($spans) === 2); foreach ($spans as $span) { \assert($span instanceof \DOMElement); \assert($span->ownerDocument === $doc); } foreach ($spans as $span) { \assert($span instanceof \DOMElement); // This call will fail for the second `<span>`. It does not really // matter what is accessed here, the error message will be the same. $span->hasAttribute('test'); while ($span->childNodes->length) { $span->removeChild($span->childNodes[0]); } $span->appendChild( $span->ownerDocument->createTextNode('Hello World') ); } echo $span[0]->textContent . "\n"; // Hello World
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 48
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 48
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 48
2 jumps found. (Code = 77) Position 1 = 50, Position 2 = 78
Branch analysis from position: 50
2 jumps found. (Code = 78) Position 1 = 51, Position 2 = 78
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 61
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 61
Branch analysis from position: 70
Branch analysis from position: 61
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
Branch analysis from position: 48
Branch analysis from position: 24
filename:       /in/uSEC9
function name:  (null)
number of ops:  84
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $spans, !4 = $span
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, '%3Cp%3E%0A++++%3Cspan%3E%0A++++++++%3Cstrong%3E%0A++++++++++++%3Cspan%3E%0A++++++++++++++++Test%0A++++++++++++%3C%2Fspan%3E%0A++++++++%3C%2Fstrong%3E%0A++++%3C%2Fspan%3E%0A%3C%2Fp%3E'
   14     1        NEW                                                  $6      'DOMDocument'
          2        SEND_VAL_EX                                                  '1.0'
          3        SEND_VAL_EX                                                  'UTF-8'
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !1, $6
   15     6        INIT_METHOD_CALL                                             !1, 'loadHTML'
   16     7        CONCAT                                               ~9      '%3Chtml%3E%3Chead%3E%3Cmeta+http-equiv%3D%22Content-Type%22+content%3D%22text%2Fhtml%3B+charset%3Dutf-8%22+%2F%3E%3C%2Fhead%3E%3Cbody%3E', !0
          8        CONCAT                                               ~10     ~9, '%3C%2Fbody%3E%3C%2Fhtml%3E'
          9        SEND_VAL_EX                                                  ~10
   15    10        DO_FCALL                                          0          
   18    11        NEW                                                  $12     'DOMXPath'
         12        SEND_VAR_EX                                                  !1
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !2, $12
   20    15        ASSIGN                                                       !3, <array>
   21    16        INIT_METHOD_CALL                                             !2, 'query'
         17        SEND_VAL_EX                                                  '%2F%2Fspan'
         18        DO_FCALL                                          0  $16     
         19      > FE_RESET_R                                           $17     $16, ->24
         20    > > FE_FETCH_R                                                   $17, !4, ->24
   22    21    >   ASSIGN_DIM                                                   !3
         22        OP_DATA                                                      !4
   21    23      > JMP                                                          ->20
         24    >   FE_FREE                                                      $17
   25    25        ASSERT_CHECK                                                 
         26        INIT_FCALL                                                   'assert'
         27        COUNT                                                ~19     !3
         28        IS_IDENTICAL                                         ~20     ~19, 2
         29        SEND_VAL                                                     ~20
         30        SEND_VAL                                                     'assert%28%5Ccount%28%24spans%29+%3D%3D%3D+2%29'
         31        DO_ICALL                                                     
   27    32      > FE_RESET_R                                           $22     !3, ->48
         33    > > FE_FETCH_R                                                   $22, !4, ->48
   28    34    >   ASSERT_CHECK                                                 
         35        INIT_FCALL                                                   'assert'
         36        INSTANCEOF                                           ~23     !4, 'DOMElement'
         37        SEND_VAL                                                     ~23
         38        SEND_VAL                                                     'assert%28%24span+instanceof+%5CDOMElement%29'
         39        DO_ICALL                                                     
   29    40        ASSERT_CHECK                                                 
         41        INIT_FCALL                                                   'assert'
         42        FETCH_OBJ_R                                          ~25     !4, 'ownerDocument'
         43        IS_IDENTICAL                                         ~26     !1, ~25
         44        SEND_VAL                                                     ~26
         45        SEND_VAL                                                     'assert%28%24span-%3EownerDocument+%3D%3D%3D+%24doc%29'
         46        DO_ICALL                                                     
   27    47      > JMP                                                          ->33
         48    >   FE_FREE                                                      $22
   32    49      > FE_RESET_R                                           $28     !3, ->78
         50    > > FE_FETCH_R                                                   $28, !4, ->78
   33    51    >   ASSERT_CHECK                                                 
         52        INIT_FCALL                                                   'assert'
         53        INSTANCEOF                                           ~29     !4, 'DOMElement'
         54        SEND_VAL                                                     ~29
         55        SEND_VAL                                                     'assert%28%24span+instanceof+%5CDOMElement%29'
         56        DO_ICALL                                                     
   37    57        INIT_METHOD_CALL                                             !4, 'hasAttribute'
         58        SEND_VAL_EX                                                  'test'
         59        DO_FCALL                                          0          
   39    60      > JMP                                                          ->67
   40    61    >   INIT_METHOD_CALL                                             !4, 'removeChild'
         62        CHECK_FUNC_ARG                                               
         63        FETCH_OBJ_FUNC_ARG                                   $32     !4, 'childNodes'
         64        FETCH_DIM_FUNC_ARG                                   $33     $32, 0
         65        SEND_FUNC_ARG                                                $33
         66        DO_FCALL                                          0          
   39    67    >   FETCH_OBJ_R                                          ~35     !4, 'childNodes'
         68        FETCH_OBJ_R                                          ~36     ~35, 'length'
         69      > JMPNZ                                                        ~36, ->61
   42    70    >   INIT_METHOD_CALL                                             !4, 'appendChild'
   43    71        FETCH_OBJ_R                                          ~37     !4, 'ownerDocument'
         72        INIT_METHOD_CALL                                             ~37, 'createTextNode'
         73        SEND_VAL_EX                                                  'Hello+World'
         74        DO_FCALL                                          0  $38     
         75        SEND_VAR_NO_REF_EX                                           $38
   42    76        DO_FCALL                                          0          
   32    77      > JMP                                                          ->50
         78    >   FE_FREE                                                      $28
   47    79        FETCH_DIM_R                                          ~40     !4, 0
         80        FETCH_OBJ_R                                          ~41     ~40, 'textContent'
         81        CONCAT                                               ~42     ~41, '%0A'
         82        ECHO                                                         ~42
         83      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.48 ms | 486 KiB | 8 Q