如何覆盖 Slim 的第 2 版默认错误处理?我不希望我的应用程序在每次收到警告消息时崩溃。基本上我想从 \Slim\Slim 类中覆盖函数 handleErrors() 。
我研究了如何覆盖这种行为,但因为它被称为:
set_error_handler(array('\Slim\Slim', 'handleErrors'));
在 Sim 的 run() 方法中,我必须自己编辑 Slim 源代码。我将上面的内容更改为:set_error_handler(array(get_class($this), 'handleErrors'));
然后我为 handleErrors() 使用不同的行为扩展了 Slim,并实例化了我的自定义类而不是 Slim。它工作正常但我不想触及 Slim 的核心课程。代码仅供参考
public static function handleErrors($errno, $errstr = '', $errfile = '', $errline = '')
{
if (error_reporting() & $errno) {
//Custom Block start here
$search = 'Use of undefined constant';
if(preg_match("/{$search}/i", $errstr)) {
return true; //If undefined constant warning came will not throw exception
}
//Custom Block stop here
throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
}
return true;
}
请帮助使用正确的方法来覆盖 handleErrors()