3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $errorTypes = [ E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parse Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_USER_DEPRECATED => 'Deprecated', E_STRICT => 'Strict Standards', E_RECOVERABLE_ERROR => 'Catchable Fatal' ]; $fatalErrorTypes = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR]; function log_error($num, $str, $file, $line, $context = null, $exit = true) { global $errorTypes; global $fatalErrorTypes; $bFatal = true; if (isset($errorTypes[$num])) { $errType = $errorTypes[$num]; $bFatal = in_array($num, $fatalErrorTypes); } else { $errType = "Unknown error #$num"; } // would normally record stuff here echo "PHP $errType [$file:$line]: $str\n"; if ($bFatal && $exit) { die; } } function check_for_fatal() { global $fatalErrorTypes; $error = error_get_last(); if (in_array($error['type'], $fatalErrorTypes)) { log_error($error["type"], $error["message"], $error["file"], $error["line"], null, false); $output = '{"errors":[{"code":"internal_server_error"}]}'; // would normally record stuff here echo $output; } } function log_exception(\Exception $e) { echo get_class($e) . ': ' . $e->getMessage(); } register_shutdown_function('check_for_fatal'); set_error_handler('log_error'); set_exception_handler('log_exception'); try { $broken = null; echo $broken->length(); } catch (\Exception $e) { log_exception($e); }
based on koMt3
Output for 7.0.0 - 7.2.6
Fatal error: Uncaught TypeError: Argument 1 passed to log_exception() must be an instance of Exception, instance of Error given in /in/q0kfh:56 Stack trace: #0 [internal function]: log_exception(Object(Error)) #1 {main} thrown in /in/q0kfh on line 56 PHP Error [/in/q0kfh:56]: Uncaught TypeError: Argument 1 passed to log_exception() must be an instance of Exception, instance of Error given in /in/q0kfh:56 Stack trace: #0 [internal function]: log_exception(Object(Error)) #1 {main} thrown {"errors":[{"code":"internal_server_error"}]}
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Fatal error: Call to a member function length() on null in /in/q0kfh on line 66 PHP Error [/in/q0kfh:66]: Call to a member function length() on null {"errors":[{"code":"internal_server_error"}]}
Process exited with code 255.
Output for 5.4.0 - 5.5.35
Fatal error: Call to a member function length() on a non-object in /in/q0kfh on line 66 PHP Error [/in/q0kfh:66]: Call to a member function length() on a non-object {"errors":[{"code":"internal_server_error"}]}
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/q0kfh on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/q0kfh on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/q0kfh on line 3
Process exited with code 255.