问题描述
我有以下代码:
set_error_handler(
function ($errno,$errstr,$errfile,$errline,array $errcontex) {
throw new Exception($errstr,0);
},E_ALL
);
class Foo
{
public function asd(): int
{
return 0;
}
}
class Bar
{
public function asd(): int
{
return 1;
}
}
$a = [
1 => new Foo(),2 => new Bar(),];
try {
array_diff([],$a);
} catch (Throwable $exception)
{
var_dump("11");
}
当我运行它时,它导致以下错误:PHP Warning: Uncaught Exception: Object of class Foo could not be converted to string in /oms/bebe.php:5 Stack trace: ...
。也就是说,尽管有set_error_handler
到位,但似乎没有捕获到异常。当我声明带有单个元素的$a
数组时,更奇怪的是,
$a = [
2 => new Bar(),];
一切正常,也就是说,捕获到异常并输出11
。
为什么?以及如何捕获具有任意数组元素数量的异常?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)