3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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';
based on jqSEv
Output for 7.2.0
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 5.3.18 - 7.1.10
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