3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <div class="blockImg imgRight"> <img src="customs/2/pictures/home.png"> <figcaption>Une légende</figcaption> </div> HTML; $dom = \Dom\HTMLDocument::createFromString($html, LIBXML_NOERROR); $divNode = $dom->querySelector('div.blockImg'); $classList = $divNode?->classList; if ($divNode and $classList->contains('imgRight') || $classList->contains('imgLeft')) { $class = $classList->contains('imgRight') ? 'imgRight' : 'imgLeft'; $src = $divNode->querySelector('img')->getAttribute('src'); $caption = $divNode->querySelector('figcaption')->textContent; echo $class, PHP_EOL, $src, PHP_EOL, $caption, PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 50
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 22
Branch analysis from position: 23
filename:       /in/NHjFs
function name:  (null)
number of ops:  51
compiled vars:  !0 = $html, !1 = $dom, !2 = $divNode, !3 = $classList, !4 = $class, !5 = $src, !6 = $caption
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv+class%3D%22blockImg+imgRight%22%3E%0A%09%3Cimg+src%3D%22customs%2F2%2Fpictures%2Fhome.png%22%3E%0A%09%3Cfigcaption%3EUne+l%C3%A9gende%3C%2Ffigcaption%3E%0A%3C%2Fdiv%3E'
   10     1        INIT_STATIC_METHOD_CALL                                  'Dom%5CHTMLDocument', 'createFromString'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              32
          4        DO_FCALL                                      0  $8      
          5        ASSIGN                                                   !1, $8
   12     6        INIT_METHOD_CALL                                         !1, 'querySelector'
          7        SEND_VAL_EX                                              'div.blockImg'
          8        DO_FCALL                                      0  $10     
          9        ASSIGN                                                   !2, $10
   14    10        JMP_NULL                                         ~12     !2
         11        FETCH_OBJ_R                                      ~12     !2, 'classList'
         12        ASSIGN                                                   !3, ~12
   16    13      > JMPZ_EX                                          ~14     !2, ->23
         14    >   INIT_METHOD_CALL                                         !3, 'contains'
         15        SEND_VAL_EX                                              'imgRight'
         16        DO_FCALL                                      0  $15     
         17      > JMPNZ_EX                                         ~16     $15, ->22
         18    >   INIT_METHOD_CALL                                         !3, 'contains'
         19        SEND_VAL_EX                                              'imgLeft'
         20        DO_FCALL                                      0  $17     
         21        BOOL                                             ~16     $17
         22    >   BOOL                                             ~14     ~16
         23    > > JMPZ                                                     ~14, ->50
   17    24    >   INIT_METHOD_CALL                                         !3, 'contains'
         25        SEND_VAL_EX                                              'imgRight'
         26        DO_FCALL                                      0  $18     
         27      > JMPZ                                                     $18, ->30
         28    >   QM_ASSIGN                                        ~19     'imgRight'
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~19     'imgLeft'
         31    >   ASSIGN                                                   !4, ~19
   18    32        INIT_METHOD_CALL                                         !2, 'querySelector'
         33        SEND_VAL_EX                                              'img'
         34        DO_FCALL                                      0  $21     
         35        INIT_METHOD_CALL                                         $21, 'getAttribute'
         36        SEND_VAL_EX                                              'src'
         37        DO_FCALL                                      0  $22     
         38        ASSIGN                                                   !5, $22
   19    39        INIT_METHOD_CALL                                         !2, 'querySelector'
         40        SEND_VAL_EX                                              'figcaption'
         41        DO_FCALL                                      0  $24     
         42        FETCH_OBJ_R                                      ~25     $24, 'textContent'
         43        ASSIGN                                                   !6, ~25
   21    44        ECHO                                                     !4
         45        ECHO                                                     '%0A'
         46        ECHO                                                     !5
         47        ECHO                                                     '%0A'
         48        ECHO                                                     !6
         49        ECHO                                                     '%0A'
   22    50    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.99 ms | 1017 KiB | 13 Q