3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); set_error_handler( /** * @throws ErrorException */ static function ($errno, $errstr, $errfile, $errline): void { throw new ErrorException($errstr, $errno, $errno, $errfile, $errline); } ); try { @trigger_error('Oh no'); } catch (ErrorException $good) { assert('Oh no' === $good->getMessage(), get_class($good)); } finally { assert(isset($good), 'an expected exception was not thrown'); } unset($good); var_dump(error_get_last()); try { @trigger_error('Oh no'); } catch (ErrorException $good) { assert('Oh no' === $good->getMessage(), get_class($good)); } finally { assert(isset($good), 'an expected exception was not thrown'); } unset($good); assert(NULL === error_get_last()); try { set_error_handler(null); @trigger_error('Oh no'); restore_error_handler(); try { @trigger_error('Oh no'); } catch (ErrorException $good) { assert('Oh no' === $good->getMessage(), get_class($good)); } finally { assert(isset($good), 'an expected exception was not thrown'); } } catch (ErrorException $fail) { assert(false, sprintf('the "%s" exception must not be thrown', get_class($fail))); } finally { assert(!isset($fail), 'there must not have been any exception'); } var_dump(error_get_last());

preferences:
26.85 ms | 410 KiB | 5 Q