php7.4报错:Trying to access array offset on value of type null

编程知识 更新时间:2023-04-06 10:46:56

  • 一、说明
  • 二、原因
  • 三、解决
    • 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

本文发布于:2023-04-06 10:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/775b49411e033086b5c7a66d55d596d2.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   access   array   null   type

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 49133文章数
  • 14阅读数
  • 0评论数