3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class bar { public static function foo($data) { return $data; } } class post { public static function respond($status, $values = NULL) { if($values != NULL){ echo json_encode(['status' => $status, 'values' => $values]); return true; }else{ echo json_encode(['status' => $status]); return true; } return false; } public static function respond_catch($function) { try{ $values = $function(); } catch(Exception $e) { if($e->getMessage() != NULL ){ //There is a message echo json_encode(['status' => $default_message]); return false; }else{ //otherwise echo json_encode(['status' => 'Nastala chyba. Skúste to znova prosím.']); return false; } } echo json_encode(['status' => 'OK', 'values' => $values]); return true; } } $data = ['some','data']; post::respond_catch( function($data = $data){ return bar::foo($data); });
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined variable: data in /in/emWTS on line 51 {"status":"OK","values":null}
Output for 5.4.0 - 5.4.30
Parse error: syntax error, unexpected '$data' (T_VARIABLE) in /in/emWTS on line 49
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '[', expecting ')' in /in/emWTS on line 15
Process exited with code 255.