3v4l.org

run code in 300+ PHP versions simultaneously
<?php function myErrorHandler($errno, $errstr, $errfile, $errline) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting return; } switch ($errno) { case E_USER_ERROR: echo "<b>My ERROR</b> [$errno] $errstr<br />\n"; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; exit(1); break; case E_USER_WARNING: echo "<b>My WARNING</b> [$errno] $errstr<br />\n"; break; case E_USER_NOTICE: echo "<b>My NOTICE</b> [$errno] $errstr<br />\n"; break; case E_NOTICE: echo "Notice error type: [$errno] $errstr<br />\n"; break; default: echo "Unknown error type: [$errno] $errstr<br />\n"; break; } /* Don't execute PHP internal error handler */ return true; } function your_err_handler($errno, $errstr, $errfile, $errline, $errcontext) { $l = error_reporting(); if ( $l & $errno ) { $exit = false; switch ( $errno ) { case E_USER_ERROR: $type = 'Fatal Error'; $exit = true; break; case E_USER_WARNING: case E_WARNING: $type = 'Warning'; break; case E_USER_NOTICE: case E_NOTICE: case @E_STRICT: $type = 'Notice'; $exit = true; break; case @E_RECOVERABLE_ERROR: $type = 'Catchable'; break; default: $type = 'Unknown Error'; $exit = true; break; } $exception = new \ErrorException($type.': '.$errstr, 0, $errno, $errfile, $errline); if ( $exit ) { exc_handler($exception); exit(); } else throw $exception; } return false; } function exc_handler($exception) { $log = $exception->getMessage() . "\n" . $exception->getTraceAsString() . LINEBREAK; if ( ini_get('log_errors') ) error_log($log, 0); print("Unhandled Exception" . (DEBUG ? " - $log" : '')); } set_error_handler("your_err_handler"); $p = null; var_dump(isset($p)); var_dump(empty($p)); var_dump(is_null($p)); var_dump(isset($q)); var_dump(empty($q)); try{ var_dump(is_null($q)); } catch (Exception $e) { echo 'not set'; // throw new ErrorException($message, 0, $severity, $file, $line); } echo 'continuing';
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
bool(false) bool(true) bool(true) bool(false) bool(true) Fatal error: Uncaught ArgumentCountError: Too few arguments to function your_err_handler(), 4 passed in /in/FH46U on line 95 and exactly 5 expected in /in/FH46U:39 Stack trace: #0 /in/FH46U(95): your_err_handler(2, 'Undefined varia...', '/in/FH46U', 95) #1 {main} thrown in /in/FH46U on line 39
Process exited with code 255.
Output for 8.0.0 - 8.0.30
bool(false) bool(true) bool(true) bool(false) bool(true) Fatal error: Uncaught ArgumentCountError: Too few arguments to function your_err_handler(), 4 passed and exactly 5 expected in /in/FH46U:39 Stack trace: #0 /in/FH46U(95): your_err_handler(2, 'Undefined varia...', '/in/FH46U', 95) #1 {main} thrown in /in/FH46U on line 39
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
bool(false) bool(true) bool(true) bool(false) bool(true) Warning: Use of undefined constant LINEBREAK - assumed 'LINEBREAK' (this will throw an Error in a future version of PHP) in /in/FH46U on line 81 Warning: Use of undefined constant DEBUG - assumed 'DEBUG' (this will throw an Error in a future version of PHP) in /in/FH46U on line 84 Unhandled Exception - Notice: Undefined variable: q #0 /in/FH46U(95): your_err_handler(8, 'Undefined varia...', '/in/FH46U', 95, Array) #1 {main}LINEBREAK
Output for 7.3.32 - 7.3.33
bool(false) bool(true) bool(true) bool(false) bool(true) bool(true) continuing
Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25
bool(false) bool(true) bool(true) bool(false) bool(true) Notice: Use of undefined constant LINEBREAK - assumed 'LINEBREAK' in /in/FH46U on line 81 Notice: Use of undefined constant DEBUG - assumed 'DEBUG' in /in/FH46U on line 84 Unhandled Exception - Notice: Undefined variable: q #0 /in/FH46U(95): your_err_handler(8, 'Undefined varia...', '/in/FH46U', 95, Array) #1 {main}LINEBREAK

preferences:
239.06 ms | 403 KiB | 242 Q