- error_reporting: documentation ( source)
- set_error_handler: documentation ( source)
<?php
convertPhpErrorsToExceptions();
$array = ['hi' => 'dsa'];
echo $array['unknown'];
function convertPhpErrorsToExceptions()
{
static $isNotLoaded = true;
if ($isNotLoaded) {
set_error_handler('phpErrorToException');
$isNotLoaded = false;
}
}
function phpErrorToException($severity, $message, $filename, $lineno)
{
if (error_reporting() & $severity) {
throw new \ErrorException($message, 0, $severity, $filename, $lineno);
}
}