php7.4报错:Trying to access array offset on value of type null
一、说明二、原因三、解决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
文章共503字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
一、说明
- 报错原因:访问类型为
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.net/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 {
}
更多推荐
已为社区贡献10条内容
所有评论(0)