- 一、说明
- 二、原因
- 三、解决
- 1、原代码
- 2、修改后
一、说明
- 报错原因:访问类型为
null
的值的 数组下标 7.2
中是没问题的,7.4
中对语法规范性更为严谨
二、原因
- 原文:
Trying to use values of type null, bool, int, float or resource as an array (such as $null["key"]) will now generate a notice.
- 翻译:尝试将 null,bool,int,float 或 resource 类型的值用作数组 ( 例如 $null[“key”] ) 会产生一个通知。
- 传送门:https://www.php/manual/en/migration74.incompatible.php,截图如下:
三、解决
1、原代码
$result = $userDao->getOne();
if($result['status'] == 1) {
} else {
}
2、修改后
$result = $userDao->getOne();
if(!empty($result['status']) && ($result['status'] == 1)) {
} else {
}
更多推荐
php7.4报错:Trying to access array offset on value of type null
发布评论