3v4l.org

run code in 300+ PHP versions simultaneously
<?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'); } trigger_error('boo'); 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); } 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'); } include dirname(__FILE__) . '../modules/frontend/views/error/exception.phtml'; 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 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Exception: boo in /in/W6IZH at line 31 in /in/W6IZH:58 Stack trace: #0 [internal function]: {closure}(1024, 'boo', '/in/W6IZH', 31) #1 /in/W6IZH(31): trigger_error('boo') #2 /in/W6IZH(140): handleException(Object(Exception)) #3 {main} thrown in /in/W6IZH on line 58 Fatal error: Uncaught Exception: boo in /in/W6IZH at line 31 in /in/W6IZH:58 Stack trace: #0 [internal function]: {closure}(1024, 'boo', '/in/W6IZH', 31) #1 /in/W6IZH(31): trigger_error('boo') #2 /in/W6IZH(48): handleException(Object(Exception)) #3 [internal function]: {closure}() #4 {main} thrown in /in/W6IZH on line 58
Process exited with code 255.
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.33
Fatal error: Uncaught Exception: boo in /in/W6IZH at line 31 in /in/W6IZH:58 Stack trace: #0 [internal function]: {closure}(1024, 'boo', '/in/W6IZH', 31, Array) #1 /in/W6IZH(31): trigger_error('boo') #2 /in/W6IZH(140): handleException(Object(Exception)) #3 {main} thrown in /in/W6IZH on line 58 Fatal error: Uncaught Exception: boo in /in/W6IZH at line 31 in /in/W6IZH:58 Stack trace: #0 [internal function]: {closure}(1024, 'boo', '/in/W6IZH', 31, Array) #1 /in/W6IZH(31): trigger_error('boo') #2 /in/W6IZH(48): handleException(Object(Exception)) #3 [internal function]: {closure}() #4 {main} thrown in /in/W6IZH on line 58
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Uncaught exception 'Exception' with message 'boo in /in/W6IZH at line 31' in /in/W6IZH:58 Stack trace: #0 [internal function]: {closure}(1024, 'boo', '/in/W6IZH', 31, Array) #1 /in/W6IZH(31): trigger_error('boo') #2 /in/W6IZH(140): handleException(Object(Exception)) #3 {main} thrown in /in/W6IZH on line 58 Fatal error: Uncaught exception 'Exception' with message 'boo in /in/W6IZH at line 31' in /in/W6IZH:58 Stack trace: #0 [internal function]: {closure}(1024, 'boo', '/in/W6IZH', 31, Array) #1 /in/W6IZH(31): trigger_error('boo') #2 /in/W6IZH(48): handleException(Object(Exception)) #3 [internal function]: {closure}() #4 {main} thrown in /in/W6IZH on line 58
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/W6IZH on line 55
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/W6IZH on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/W6IZH on line 25 Parse error: syntax error, unexpected T_FUNCTION in /in/W6IZH on line 38
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/W6IZH</b> on line <b>8</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/W6IZH</b> on line <b>25</b><br /> <br /> <b>Parse error</b>: syntax error, unexpected T_FUNCTION in <b>/in/W6IZH</b> on line <b>38</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.0.5
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/W6IZH</b> on line <b>8</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/W6IZH</b> on line <b>25</b><br /> <br /> <b>Parse error</b>: parse error, unexpected T_FUNCTION in <b>/in/W6IZH</b> on line <b>38</b><br />
Process exited with code 255.
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected '{' in <b>/in/W6IZH</b> on line <b>2</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 '{' in <b>/in/W6IZH</b> on line <b>2</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/W6IZH</b> on line <b>2</b><br />
Process exited with code 255.

preferences:
339.11 ms | 401 KiB | 464 Q