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; } 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.24 - 8.1.28, 8.2.11 - 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/jqSEv on line 88 and exactly 5 expected in /in/jqSEv:39 Stack trace: #0 /in/jqSEv(88): your_err_handler(2, 'Undefined varia...', '/in/jqSEv', 88) #1 {main} thrown in /in/jqSEv on line 39
Process exited with code 255.
Output for 7.0.0 - 7.0.11, 7.0.13 - 7.0.14, 7.0.16 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.3, 7.2.5 - 7.2.6, 7.2.9 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
bool(false) bool(true) bool(true) bool(false) bool(true) Fatal error: Uncaught Error: Call to undefined function exc_handler() in /in/jqSEv:71 Stack trace: #0 /in/jqSEv(88): your_err_handler(8, 'Undefined varia...', '/in/jqSEv', 88, Array) #1 {main} thrown in /in/jqSEv on line 71
Process exited with code 255.
Output for 5.6.32, 7.0.12, 7.0.15, 7.2.4, 7.2.7 - 7.2.8

Process exited with code 137.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.31, 5.6.33 - 5.6.40
bool(false) bool(true) bool(true) bool(false) bool(true) Fatal error: Call to undefined function exc_handler() in /in/jqSEv on line 71
Process exited with code 255.

preferences:
200.32 ms | 402 KiB | 262 Q