Error in PHP 7.4.6: Repair of Trying to Access Array Offset on Value of Type Bool
1. Error in PHP 7.4.6: try to access array offset on value of type bool, as shown in Figure 1
2. Check the code and print $result, its value is bool(true). as shown in Figure 2
$result = $planService->ReportUpCreate($model, $planattendedUserRelations, $MaterialAssets, $identity);
var_dump($result);
exit;
if ($result['status']=== false) {
Throw new ServerErrorHttpException($result['message'], $result['code']);
}
3. Try to access an array subscript of a value of type BOOL, so an error is reported. Although it was working normally in PHP 7.2.14 before. From this analysis, it is concluded that the PHP language itself has more rigorous requirements for grammar. Refer to the official documentation: backward incompatibility changes for version 7.4, array-style access for non-arrays, and now, try to use values of null, bool, int, float or resource as an array (e.g. $null[“key”]) will generate a notification. https://www.php.net/manual/en/migration74.incompatible.php . as shown in Figure 3
4. Edit the code, and the condition judgment is adjusted to: !$result. Normal operation, no errors are reported again
$result = $planService->ReportUpCreate($model, $planattendedUserRelations, $MaterialAssets, $identity);
if (!$result) {
Throw new ServerErrorHttpException($result['message'], $result['code']);
}


![尝试访问类型为 bool 的值的数组下标,因此报错。虽然之前在 PHP 7.2.14 中是正常运行的。由此分析得出,PHP 语言本身对于语法的规范性要求得更为严谨了的。参考官方文档:7.4 版本的向后不兼容更改,非数组的数组样式访问,现在,尝试将 null,bool,int,float 或 resource 类型的值用作数组 ( 例如 $null["key"] ) 会产生一个通知。](https://www.shuijingwanwq.com/wp-content/uploads/2020/06/3-4.png)