Notice: Trying to access array offset on value of type null in /xxxx/xxx.php

Notice: Trying to access array offset on value of type null in /xxxx/xxx.php

wordpress用了wp weixin插件,更换环境后,在用户列表出现报错,太坑爹了,提示:

Notice: Trying to access array offset on value of type null in /xxxx/plugins/wp-weixin/inc/class-wp-weixin.php on line 661

报错访问类型为NULL的值的数组下标,虽然之前在 PHP 7.0 中是正常运行的。参考官方文档:7.4 版本的向后不兼容更改,非数组的数组样式访问,现在,尝试将 null,bool,int,float 或 resource 类型的值用作数组 ( 例如 $null[“key”] ) 会产生一个通知。

https://www.php.net/manual/en/migration74.incompatible.php

Notice: Trying to access array offset on value of type null in /xxxx/xxx.php

foreach ( $this->meta_keys as $key ) {
                
            if ( $meta_key === $key ) {
                $raw_data = json_decode( get_user_meta( $object_id, 'wp_weixin_rawdata', true ), true );
                $raw_key  = str_replace( 'wp_weixin_', '', $key );
                $check  = ( $single ) ? $raw_data[ $raw_key ] : array( $raw_data[ $raw_key ] );
                break;
            }
        }        
        return $check;

var_dump了$raw_data,发现最后几次遍历是NULL。考虑加个判断,当$raw_data为NULL时跳过,否则继续。

foreach ( $this->meta_keys as $key ) {
                
            if ( $meta_key === $key ) {
                $raw_data = json_decode( get_user_meta( $object_id, 'wp_weixin_rawdata', true ), true );
                $raw_key  = str_replace( 'wp_weixin_', '', $key );
                if(is_null($raw_data) ){
                    continue;
                }else{
                    $check  = ( $single ) ? $raw_data[ $raw_key ] : array( $raw_data[ $raw_key ] );
                }
                break;
            }
        }
        
        return $check;

完美解决问题!

本文作者:𝙕𝙆𝘾𝙊𝙄

文章名称:Notice: Trying to access array offset on value of type null in /xxxx/xxx.php

文章链接:https://www.zkcoi.com/365up/program/1080.html

本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
𝙕𝙆𝘾𝙊𝙄𝙕𝙆𝘾𝙊𝙄
上一篇 2022年1月2日 下午10:16
下一篇 2022年3月28日 下午2:00

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

私聊博主

立即联系
一般有空就回复

qrcode_web

微信扫码联系我

分享本页
返回顶部