3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 hhvm-3.20.2 - 3.21.3, 7.0.0 - 7.3.0beta1
Notice: Undefined index: REQUEST_METHOD in /in/biuep on line 49 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for hhvm-3.22.0
Notice: Undefined index: REQUEST_METHOD in /in/biuep on line -1 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for hhvm-3.11.1 - 3.19.2
Notice: Undefined index: REQUEST_METHOD in /in/biuep on line 49 Warning: mb_strtolower() expects parameter 1 to be string, null given in /in/biuep on line 49 {"status":0,"msg":"Wrong HTTP method","data":[]}
Output for hhvm-3.10.1
Notice: Undefined index: REQUEST_METHOD in /in/biuep on line 49 Catchable fatal error: Argument 1 passed to Response::error() must be an instance of string, string given in /in/biuep on line 14
Process exited with code 255.
Output for 5.4.0 - 5.6.30
Notice: Undefined index: REQUEST_METHOD in /in/biuep on line 49 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.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/biuep on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/biuep on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/biuep on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/biuep on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/biuep on line 5
Process exited with code 255.