3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php try { if (!function_exists('handleException')) { /** * @param \Exception $e * @return string readable message */ function logException(\Exception $e) { $type = get_class($e); $msg = $e->getMessage(); $trace = $e->getTraceAsString(); global $logger; if (isset($logger)) { $logger->error(sprintf("%s: %s\n%s", $type, $msg, $trace)); if (method_exists($logger, 'newrelicLog')) { $logger->newrelicLog($e); } } return sprintf("<h1>%s</h1><pre>%s<br/><h2>Debug Trace:</h2>%s</pre>", $type, $msg, $trace); } function handleException(\Exception $e) { $message = logException($e); if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } $foo = APPLICATION_PATH; exit(); } } if (!isset($shutdownFunction)) { $shutdownFunction = function () { try { $error = error_get_last(); if (isset($error)) { throw new \Exception( $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line'], $error['type'] ); } } catch (Exception $e) { handleException($e); } }; register_shutdown_function($shutdownFunction); } if (!isset($errorHandler)) { $errorHandler = function ($errno, $errstr, $errfile = null, $errline = null, $errcontext = []) { // prevent exception to be thrown when error_reporting is turned off or suppressed with @ if (error_reporting() !== 0) { throw new \Exception("$errstr in $errfile at line $errline", $errno); } else { echo "log $errstr in $errfile at line $errline"; } }; set_error_handler($errorHandler); } throw new \Exception('after first'); define('APPLICATION_PATH', 'foo'); if (!function_exists('handleException')) { /** * @param \Exception $e * @return string readable message */ function logException(\Exception $e) { $type = get_class($e); $msg = $e->getMessage(); $trace = $e->getTraceAsString(); global $logger; if (isset($logger)) { $logger->error(sprintf("%s: %s\n%s", $type, $msg, $trace)); if (method_exists($logger, 'newrelicLog')) { $logger->newrelicLog($e); } } return sprintf("<h1>%s</h1><pre>%s<br/><h2>Debug Trace:</h2>%s</pre>", $type, $msg, $trace); } function handleException(\Exception $e) { $message = logException($e); if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } $foo = APPLICATION_PATH; exit(); } } if (!isset($shutdownFunction)) { $shutdownFunction = function () { try { $error = error_get_last(); if (isset($error)) { throw new \Exception( $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line'], $error['type'] ); } } catch (Exception $e) { handleException($e); } }; register_shutdown_function($shutdownFunction); } if (!isset($errorHandler)) { $errorHandler = function ($errno, $errstr, $errfile = null, $errline = null, $errcontext = []) { // prevent exception to be thrown when error_reporting is turned off or suppressed with @ if (error_reporting() !== 0) { throw new \Exception("$errstr in $errfile at line $errline", $errno); } else { echo "log $errstr in $errfile at line $errline"; } }; set_error_handler($errorHandler); } throw new \Exception('after both'); } catch (\Exception $e) { handleException($e); }
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Exception: Use of undefined constant APPLICATION_PATH - assumed 'APPLICATION_PATH' in /in/PsVQd at line 31 in /in/PsVQd:58 Stack trace: #0 /in/PsVQd(31): {closure}(8, 'Use of undefine...', '/in/PsVQd', 31, Array) #1 /in/PsVQd(142): handleException(Object(Exception)) #2 {main} thrown in /in/PsVQd on line 58 Fatal error: Uncaught Exception: Use of undefined constant APPLICATION_PATH - assumed 'APPLICATION_PATH' in /in/PsVQd at line 31 in /in/PsVQd:58 Stack trace: #0 /in/PsVQd(31): {closure}(8, 'Use of undefine...', '/in/PsVQd', 31, Array) #1 /in/PsVQd(48): handleException(Object(Exception)) #2 [internal function]: {closure}() #3 {main} thrown in /in/PsVQd on line 58
Process exited with code 255.
Output for hhvm-3.12.0
Fatal error: Uncaught exception 'Exception' with message 'Use of undefined constant APPLICATION_PATH - assumed 'APPLICATION_PATH' in /in/PsVQd at line 31' in /in/PsVQd:58 Stack trace: #0 /in/PsVQd(31): Closure$handleException#2() #1 /in/PsVQd(142): handleException() #2 {main} Fatal error: Uncaught exception 'Exception' with message 'Use of undefined constant APPLICATION_PATH - assumed 'APPLICATION_PATH' in /in/PsVQd at line 31' in /in/PsVQd:58 Stack trace: #0 /in/PsVQd(31): Closure$handleException#2() #1 /in/PsVQd(48): handleException() #2 (): Closure$handleException() #3 {main}
Process exited with code 255.
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.4.0 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'Use of undefined constant APPLICATION_PATH - assumed 'APPLICATION_PATH' in /in/PsVQd at line 31' in /in/PsVQd:58 Stack trace: #0 /in/PsVQd(31): {closure}(8, 'Use of undefine...', '/in/PsVQd', 31, Array) #1 /in/PsVQd(142): handleException(Object(Exception)) #2 {main} thrown in /in/PsVQd on line 58 Fatal error: Uncaught exception 'Exception' with message 'Use of undefined constant APPLICATION_PATH - assumed 'APPLICATION_PATH' in /in/PsVQd at line 31' in /in/PsVQd:58 Stack trace: #0 /in/PsVQd(31): {closure}(8, 'Use of undefine...', '/in/PsVQd', 31, Array) #1 /in/PsVQd(48): handleException(Object(Exception)) #2 [internal function]: {closure}() #3 {main} thrown in /in/PsVQd on line 58
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/PsVQd on line 55
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/PsVQd on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/PsVQd on line 25 Parse error: syntax error, unexpected T_FUNCTION in /in/PsVQd on line 38
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/PsVQd on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/PsVQd on line 25 Parse error: parse error, unexpected T_FUNCTION in /in/PsVQd on line 38
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '{' in /in/PsVQd on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '{' in /in/PsVQd on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/PsVQd on line 2
Process exited with code 255.