3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Checks if a XML file's structure is valid. * @author Julius Beckmann <php@h4cc.de> * @param $file string * @return bool */ function isXmlStructureValid($file) { $prev = libxml_use_internal_errors(true); $ret = true; try { new SimpleXMLElement($file, 0, true); } catch(Exception $e) { $ret = false; } if(count(libxml_get_errors()) > 0) { // There has been XML errors $ret = false; } // Tidy up. libxml_clear_errors(); libxml_use_internal_errors($prev); return $ret; } $xml = '<html> <head><title>411 Length Required</title></head> <body bgcolor="white"> <center><h1>411 Length Required</h1></center> <center>nginx</center> </body> </html>'; var_dump(isXmlStructureValid($xml));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PG9au
function name:  (null)
number of ops:  8
compiled vars:  !0 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%0A%3Chead%3E%3Ctitle%3E411+Length+Required%3C%2Ftitle%3E%3C%2Fhead%3E%0A%3Cbody+bgcolor%3D%22white%22%3E%0A%3Ccenter%3E%3Ch1%3E411+Length+Required%3C%2Fh1%3E%3C%2Fcenter%3E%0A%3Ccenter%3Enginx%3C%2Fcenter%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   36     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'isxmlstructurevalid'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function isxmlstructurevalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
Found catch point at position: 13
Branch analysis from position: 13
2 jumps found. (Code = 107) Position 1 = 14, Position 2 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
Branch analysis from position: 21
filename:       /in/PG9au
function name:  isXmlStructureValid
number of ops:  28
compiled vars:  !0 = $file, !1 = $prev, !2 = $ret, !3 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'libxml_use_internal_errors'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   11     5        ASSIGN                                                   !2, <true>
   13     6        NEW                                              $7      'SimpleXMLElement'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAL_EX                                              0
          9        SEND_VAL_EX                                              <true>
         10        DO_FCALL                                      0          
         11        FREE                                                     $7
         12      > JMP                                                      ->15
   14    13  E > > CATCH                                       last         'Exception'
   15    14    >   ASSIGN                                                   !2, <false>
   17    15    >   INIT_FCALL                                               'libxml_get_errors'
         16        DO_ICALL                                         $10     
         17        COUNT                                            ~11     $10
         18        IS_SMALLER                                               0, ~11
         19      > JMPZ                                                     ~12, ->21
   19    20    >   ASSIGN                                                   !2, <false>
   22    21    >   INIT_FCALL                                               'libxml_clear_errors'
         22        DO_ICALL                                                 
   23    23        INIT_FCALL                                               'libxml_use_internal_errors'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                                 
   24    26      > RETURN                                                   !2
   25    27*     > RETURN                                                   null

End of function isxmlstructurevalid

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.98 ms | 1403 KiB | 22 Q