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); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key "REQUEST_METHOD" in /in/biuep on line 49 Deprecated: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /in/biuep on line 49 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key "REQUEST_METHOD" in /in/biuep on line 49 Deprecated: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /in/biuep on line 49 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for 8.0.0 - 8.0.30
Warning: Undefined array key "REQUEST_METHOD" in /in/biuep on line 49 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for 7.4.26 - 7.4.33
Notice: Undefined index: REQUEST_METHOD in /in/biuep on line 49 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.25
{"status":0,"msg":"Wrong HTTP method","data":[]}
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to Response::error() must be an instance of string, string given, called in /in/biuep on line 82 and defined in /in/biuep on line 9
Process exited with code 255.
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/biuep on line 9
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected '[' in <b>/in/biuep</b> on line <b>9</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in <b>/in/biuep</b> on line <b>9</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/biuep</b> on line <b>5</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/biuep</b> on line <b>5</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in <b>/in/biuep</b> on line <b>5</b><br />
Process exited with code 255.

preferences:
320.12 ms | 401 KiB | 468 Q