I have a class called Error
which when loaded will register a function called errorHandler
using the set_error_handler
method in PHP. However, this function will return NULL
if the function fails to load or if PHP is using the default built-in error handler. I cannot figure out why my function is not being accepted. Does anyone have any good guesses?
<?php
declare (strict_types = 1);
namespace Request\Configuration;
use Errors\Exception\FatalException;
class Error extends Template
{
public static function load(): void
{
$result = set_error_handler('self::errorHandler', error_reporting());
var_dump($result);
}
public static function errorHandler(
int $number,
string $message,
string $file = null,
int $line = null,
array $context = null
) {
throw new FatalException('PHP_ERROR: ' . $message, 0);
}
}
This class when loads returns NULL
.