3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Response { public function __construnct() { header('Content-Type: application/json'); } public function error(string $msg, array $data = []){ return json_encode([ 'status' => 0, ] + compact('msg','data')); } public function success(string $msg, array $data = []) { return json_encode([ 'status' => 1, ] + compact('msg','data')); } } class View { public function render(string $file, $data = NULL) { if(stripos($file, '..')) { throw new \Exception('Invalid view'); } $dir = dirname(__FILE__); $tpl = $dir.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$file.'.tpl'; if(!file_exists($tpl)) { throw new \Exception('Missing template'); } ob_start(); include($tpl); extract(compact('data')); return ob_get_clean(); } } $response = new Response(); try { if(mb_strtolower($_SERVER['REQUEST_METHOD']) != 'post') { throw new \Exception('Wrong HTTP method'); } if(!isset($_POST['file'])) { throw new \Exception('File is not defined'); } $file = $_POST['file']; if(stripos($file, '..')) { throw new \Exception('Invalid file name'); } $file = dirname(__FILE__).DIRECTORY_SEPARATOR.$file; if(!file_exists($file)) { throw new \Exception('File not exists'); } if(pathinfo($file, PATHINFO_EXTENSION) !== 'xml') { throw new \Exception('File has wrong mimetype'); } $plan = simplexml_load_file($file); $view = new View; $html = $view->render('plan' , $plan); // pr($data); echo $response->success('File was parsed' , compact('html')); } catch (\Exception $e) { echo $response->error($e->getMessage()); } function pr($var) { echo '<pre>'; print_r($var); echo '</pre>'; } function h($var) { return htmlspecialchars($var); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 59
Branch analysis from position: 55
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 80
Branch analysis from position: 80
2 jumps found. (Code = 107) Position 1 = 81, Position 2 = -2
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  (null)
number of ops:  88
compiled vars:  !0 = $response, !1 = $file, !2 = $plan, !3 = $view, !4 = $html, !5 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $6      'Response'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $6
   49     3        INIT_FCALL                                               'mb_strtolower'
          4        FETCH_R                      global              ~9      '_SERVER'
          5        FETCH_DIM_R                                      ~10     ~9, 'REQUEST_METHOD'
          6        SEND_VAL                                                 ~10
          7        DO_ICALL                                         $11     
          8        IS_NOT_EQUAL                                             $11, 'post'
          9      > JMPZ                                                     ~12, ->14
   50    10    >   NEW                                              $13     'Exception'
         11        SEND_VAL_EX                                              'Wrong+HTTP+method'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $13
   53    14    >   FETCH_IS                                         ~15     '_POST'
         15        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     ~15, 'file'
         16        BOOL_NOT                                         ~17     ~16
         17      > JMPZ                                                     ~17, ->22
   54    18    >   NEW                                              $18     'Exception'
         19        SEND_VAL_EX                                              'File+is+not+defined'
         20        DO_FCALL                                      0          
         21      > THROW                                         0          $18
   57    22    >   FETCH_R                      global              ~20     '_POST'
         23        FETCH_DIM_R                                      ~21     ~20, 'file'
         24        ASSIGN                                                   !1, ~21
   58    25        INIT_FCALL                                               'stripos'
         26        SEND_VAR                                                 !1
         27        SEND_VAL                                                 '..'
         28        DO_ICALL                                         $23     
         29      > JMPZ                                                     $23, ->34
   59    30    >   NEW                                              $24     'Exception'
         31        SEND_VAL_EX                                              'Invalid+file+name'
         32        DO_FCALL                                      0          
         33      > THROW                                         0          $24
   62    34    >   INIT_FCALL                                               'dirname'
         35        SEND_VAL                                                 '%2Fin%2Fbiuep'
         36        DO_ICALL                                         $26     
         37        CONCAT                                           ~27     $26, '%2F'
         38        CONCAT                                           ~28     ~27, !1
         39        ASSIGN                                                   !1, ~28
   64    40        INIT_FCALL                                               'file_exists'
         41        SEND_VAR                                                 !1
         42        DO_ICALL                                         $30     
         43        BOOL_NOT                                         ~31     $30
         44      > JMPZ                                                     ~31, ->49
   65    45    >   NEW                                              $32     'Exception'
         46        SEND_VAL_EX                                              'File+not+exists'
         47        DO_FCALL                                      0          
         48      > THROW                                         0          $32
   68    49    >   INIT_FCALL                                               'pathinfo'
         50        SEND_VAR                                                 !1
         51        SEND_VAL                                                 4
         52        DO_ICALL                                         $34     
         53        IS_NOT_IDENTICAL                                         $34, 'xml'
         54      > JMPZ                                                     ~35, ->59
   69    55    >   NEW                                              $36     'Exception'
         56        SEND_VAL_EX                                              'File+has+wrong+mimetype'
         57        DO_FCALL                                      0          
         58      > THROW                                         0          $36
   72    59    >   INIT_FCALL                                               'simplexml_load_file'
         60        SEND_VAR                                                 !1
         61        DO_ICALL                                         $38     
         62        ASSIGN                                                   !2, $38
   73    63        NEW                                              $40     'View'
         64        DO_FCALL                                      0          
         65        ASSIGN                                                   !3, $40
   75    66        INIT_METHOD_CALL                                         !3, 'render'
         67        SEND_VAL_EX                                              'plan'
         68        SEND_VAR_EX                                              !2
         69        DO_FCALL                                      0  $43     
         70        ASSIGN                                                   !4, $43
   79    71        INIT_METHOD_CALL                                         !0, 'success'
         72        SEND_VAL_EX                                              'File+was+parsed'
         73        INIT_FCALL                                               'compact'
         74        SEND_VAL                                                 'html'
         75        DO_ICALL                                         $45     
         76        SEND_VAR_NO_REF_EX                                       $45
         77        DO_FCALL                                      0  $46     
         78        ECHO                                                     $46
         79      > JMP                                                      ->87
   81    80  E > > CATCH                                       last         'Exception'
   82    81    >   INIT_METHOD_CALL                                         !0, 'error'
         82        INIT_METHOD_CALL                                         !5, 'getMessage'
         83        DO_FCALL                                      0  $47     
         84        SEND_VAR_NO_REF_EX                                       $47
         85        DO_FCALL                                      0  $48     
         86        ECHO                                                     $48
   95    87    > > RETURN                                                   1

Function pr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  pr
number of ops:  7
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV                                             !0      
   88     1        ECHO                                                     '%3Cpre%3E'
   89     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   90     5        ECHO                                                     '%3C%2Fpre%3E'
   91     6      > RETURN                                                   null

End of function pr

Function h:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  h
number of ops:  6
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   RECV                                             !0      
   94     1        INIT_FCALL                                               'htmlspecialchars'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
   95     5*     > RETURN                                                   null

End of function h

Class Response:
Function __construnct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  __construnct
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-Type%3A+application%2Fjson'
          2        DO_ICALL                                                 
    7     3      > RETURN                                                   null

End of function __construnct

Function error:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  error
number of ops:  12
compiled vars:  !0 = $msg, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   11     2        INIT_FCALL                                               'json_encode'
   13     3        INIT_FCALL                                               'compact'
          4        SEND_VAL                                                 'msg'
          5        SEND_VAL                                                 'data'
          6        DO_ICALL                                         $2      
          7        ADD                                              ~3      <array>, $2
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10      > RETURN                                                   $4
   14    11*     > RETURN                                                   null

End of function error

Function success:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  success
number of ops:  12
compiled vars:  !0 = $msg, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   17     2        INIT_FCALL                                               'json_encode'
   19     3        INIT_FCALL                                               'compact'
          4        SEND_VAL                                                 'msg'
          5        SEND_VAL                                                 'data'
          6        DO_ICALL                                         $2      
          7        ADD                                              ~3      <array>, $2
          8        SEND_VAL                                                 ~3
          9        DO_ICALL                                         $4      
         10      > RETURN                                                   $4
   20    11*     > RETURN                                                   null

End of function success

End of class Response.

Class View:
Function render:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/biuep
function name:  render
number of ops:  43
compiled vars:  !0 = $file, !1 = $data, !2 = $dir, !3 = $tpl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   27     2        INIT_FCALL                                               'stripos'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '..'
          5        DO_ICALL                                         $4      
          6      > JMPZ                                                     $4, ->11
   28     7    >   NEW                                              $5      'Exception'
          8        SEND_VAL_EX                                              'Invalid+view'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $5
   31    11    >   INIT_FCALL                                               'dirname'
         12        SEND_VAL                                                 '%2Fin%2Fbiuep'
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !2, $7
   32    15        CONCAT                                           ~9      !2, '%2F'
         16        CONCAT                                           ~10     ~9, 'templates'
         17        CONCAT                                           ~11     ~10, '%2F'
         18        CONCAT                                           ~12     ~11, !0
         19        CONCAT                                           ~13     ~12, '.tpl'
         20        ASSIGN                                                   !3, ~13
   34    21        INIT_FCALL                                               'file_exists'
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                         $15     
         24        BOOL_NOT                                         ~16     $15
         25      > JMPZ                                                     ~16, ->30
   35    26    >   NEW                                              $17     'Exception'
         27        SEND_VAL_EX                                              'Missing+template'
         28        DO_FCALL                                      0          
         29      > THROW                                         0          $17
   38    30    >   INIT_FCALL                                               'ob_start'
         31        DO_ICALL                                                 
   39    32        INCLUDE_OR_EVAL                                          !3, INCLUDE
   40    33        INIT_FCALL                                               'extract'
         34        INIT_FCALL                                               'compact'
         35        SEND_VAL                                                 'data'
         36        DO_ICALL                                         $21     
         37        SEND_VAL                                                 $21
         38        DO_ICALL                                                 
   41    39        INIT_FCALL                                               'ob_get_clean'
         40        DO_ICALL                                         $23     
         41      > RETURN                                                   $23
   42    42*     > RETURN                                                   null

End of function render

End of class View.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.32 ms | 1412 KiB | 41 Q