3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = ' <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>We <em>love</em> HTML!</title> </head> <body> </body> </html> '; function run_tests( $document ) { $title = $document->getElementsByTagName( 'title' )->item( 0 ); if ( $title->childNodes->length !== 1 ) { echo "FAIL: Title tag does not have the the expected single text child. Has {$title->childNodes->length} children.\n"; } else { echo "PASS: Title tag only has a single child.\n"; } if ( $title->getElementsByTagName( 'em' )->length !== 0 ) { echo "FAIL: Title tag unexpectedly has a parsed EM child.\n"; } else { echo "PASS: Title tag has no child EM element.\n"; } if ( false !== strpos( $title->textContent, '<em>' ) ) { echo "PASS: HTML tag <em> was not parsed. Text content: {$title->textContent}\n"; } else { echo "FAIL: HTML tag <em> was parsed. Text content: {$title->textContent}\n"; } } echo "# DOMDocument:\n"; $old_document = new DOMDocument(); $old_document->loadHTML( $html ); run_tests( $old_document ); echo "\n"; echo "# Dom\HTMLDocument:\n"; if ( class_exists( Dom\HTMLDocument::class ) ) { $new_document = Dom\HTMLDocument::createFromString( $html ); run_tests( $new_document ); } else { echo "(Not available)\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oDUI3
function name:  (null)
number of ops:  25
compiled vars:  !0 = $html, !1 = $old_document, !2 = $new_document
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%0A++%3C%21DOCTYPE+html%3E%0A++%3Chtml%3E%0A+++%3Chead%3E%0A++++%3Cmeta+charset%3D%22utf-8%22%3E++%0A++++%3Ctitle%3EWe+%3Cem%3Elove%3C%2Fem%3E+HTML%21%3C%2Ftitle%3E%0A+++%3C%2Fhead%3E%0A+++%3Cbody%3E%0A+++%3C%2Fbody%3E%0A++%3C%2Fhtml%3E%0A'
   34     1        ECHO                                                         '%23+DOMDocument%3A%0A'
   35     2        NEW                                                  $4      'DOMDocument'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !1, $4
   36     5        INIT_METHOD_CALL                                             !1, 'loadHTML'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0          
   37     8        INIT_FCALL                                                   'run_tests'
          9        SEND_VAR                                                     !1
         10        DO_FCALL                                          0          
   39    11        ECHO                                                         '%0A'
   40    12        ECHO                                                         '%23+Dom%5CHTMLDocument%3A%0A'
   41    13        FRAMELESS_ICALL_1                class_exists        ~9      'Dom%5CHTMLDocument'
         14      > JMPZ                                                         ~9, ->23
   42    15    >   INIT_STATIC_METHOD_CALL                                      'Dom%5CHTMLDocument', 'createFromString'
         16        SEND_VAR                                                     !0
         17        DO_FCALL                                          0  $10     
         18        ASSIGN                                                       !2, $10
   43    19        INIT_FCALL                                                   'run_tests'
         20        SEND_VAR                                                     !2
         21        DO_FCALL                                          0          
   41    22      > JMP                                                          ->24
   45    23    >   ECHO                                                         '%28Not+available%29%0A'
   46    24    > > RETURN                                                       1

Function run_tests:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
Branch analysis from position: 39
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
Branch analysis from position: 28
filename:       /in/oDUI3
function name:  run_tests
number of ops:  45
compiled vars:  !0 = $document, !1 = $title
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
   16     1        INIT_METHOD_CALL                                             !0, 'getElementsByTagName'
          2        SEND_VAL_EX                                                  'title'
          3        DO_FCALL                                          0  $2      
          4        INIT_METHOD_CALL                                             $2, 'item'
          5        SEND_VAL_EX                                                  0
          6        DO_FCALL                                          0  $3      
          7        ASSIGN                                                       !1, $3
   17     8        FETCH_OBJ_R                                          ~5      !1, 'childNodes'
          9        FETCH_OBJ_R                                          ~6      ~5, 'length'
         10        IS_NOT_IDENTICAL                                             ~6, 1
         11      > JMPZ                                                         ~7, ->19
   18    12    >   ROPE_INIT                                         3  ~11     'FAIL%3A+Title+tag+does+not+have+the+the+expected+single+text+child.+Has+'
         13        FETCH_OBJ_R                                          ~8      !1, 'childNodes'
         14        FETCH_OBJ_R                                          ~9      ~8, 'length'
         15        ROPE_ADD                                          1  ~11     ~11, ~9
         16        ROPE_END                                          2  ~10     ~11, '+children.%0A'
         17        ECHO                                                         ~10
   17    18      > JMP                                                          ->20
   20    19    >   ECHO                                                         'PASS%3A+Title+tag+only+has+a+single+child.%0A'
   22    20    >   INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
         21        SEND_VAL_EX                                                  'em'
         22        DO_FCALL                                          0  $13     
         23        FETCH_OBJ_R                                          ~14     $13, 'length'
         24        IS_NOT_IDENTICAL                                             ~14, 0
         25      > JMPZ                                                         ~15, ->28
   23    26    >   ECHO                                                         'FAIL%3A+Title+tag+unexpectedly+has+a+parsed+EM+child.%0A'
   22    27      > JMP                                                          ->29
   25    28    >   ECHO                                                         'PASS%3A+Title+tag+has+no+child+EM+element.%0A'
   27    29    >   FETCH_OBJ_R                                          ~16     !1, 'textContent'
         30        FRAMELESS_ICALL_2                strpos              ~17     ~16, '%3Cem%3E'
         31        TYPE_CHECK                                      1018          ~17
         32      > JMPZ                                                         ~18, ->39
   28    33    >   ROPE_INIT                                         3  ~21     'PASS%3A+HTML+tag+%3Cem%3E+was+not+parsed.+Text+content%3A+'
         34        FETCH_OBJ_R                                          ~19     !1, 'textContent'
         35        ROPE_ADD                                          1  ~21     ~21, ~19
         36        ROPE_END                                          2  ~20     ~21, '%0A'
         37        ECHO                                                         ~20
   27    38      > JMP                                                          ->44
   30    39    >   ROPE_INIT                                         3  ~25     'FAIL%3A+HTML+tag+%3Cem%3E+was+parsed.+Text+content%3A+'
         40        FETCH_OBJ_R                                          ~23     !1, 'textContent'
         41        ROPE_ADD                                          1  ~25     ~25, ~23
         42        ROPE_END                                          2  ~24     ~25, '%0A'
         43        ECHO                                                         ~24
   32    44    > > RETURN                                                       null

End of function run_tests

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
171.55 ms | 2896 KiB | 10 Q