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

一、说明

  • 报错原因:访问类型为 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 {
    
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值