Skip to content

Instantly share code, notes, and snippets.

@yaredc
Last active September 9, 2019 21:22
Show Gist options
  • Save yaredc/e231d33a2ff2caeabbd45f647cbcc858 to your computer and use it in GitHub Desktop.
Save yaredc/e231d33a2ff2caeabbd45f647cbcc858 to your computer and use it in GitHub Desktop.
Fix all PHP notices and warnings with this one simple trick!
<?php
declare(strict_types=1);
/*
* Convert all notices and warnings to errors.
* There is no point in warnings and notices.
*/
set_error_handler(static function ($errno, $errstr, $errfile, $errline): bool {
switch ($errno) {
case E_WARNING:
case E_NOTICE:
throw new ErrorException($errstr, $errno, E_ERROR, $errfile, $errline);
break;
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment