Laravel 尝试捕获时出现未定义索引错误消息

Laravel 尝试捕获时出现未定义索引错误消息,laravel,laravel-8,Laravel,Laravel 8,我将代码放入Laravel中的try-catch块中,如下所示: try{ $cFollow = $string['graphql']['user']['edge_follow']['count']; }catch(\Exception $e){ $cFollow = -1; } 现在我得到了这个错误: 未定义索引:graphql 那么你知道这个错误是从哪里来的吗?我想你可能在寻找这个: $cFollow = $string['graphql']['user']['edge_f

我将代码放入Laravel中的try-catch块中,如下所示:

try{
    $cFollow = $string['graphql']['user']['edge_follow']['count'];
}catch(\Exception $e){
    $cFollow = -1;
}
现在我得到了这个错误:

未定义索引:graphql


那么你知道这个错误是从哪里来的吗?

我想你可能在寻找这个:

$cFollow = $string['graphql']['user']['edge_follow']['count'] ?? -1;
在尝试访问这些索引时,您需要确保这些索引存在,否则会出现错误:

if (isset($string['graphql']['user']['edge_follow']['count'])) {
    $cFollow = $string['graphql']['user']['edge_follow']['count'];
else {
    $cFollow = -1;
}
分为:

$cFollow = isset($string['graphql']['user']['edge_follow']['count'])
    ? $string['graphql']['user']['edge_follow']['count']
    : -1;
即:

$cFollow = $string['graphql']['user']['edge_follow']['count'] ?? -1;
isset

?:

??


请随意标记为“不是答案”。哦,等等,你不能。

是的,它来自你试图访问
$string
的索引“graphql”,但它不存在。这是否回答了你的问题?似乎这可能是一个评论,加上职业训练局的明显欺骗。