注意:升级到php 7.4后,尝试访问类型为bool的值的数组偏移量

问题描述

我刚刚将PHP版本升级到7.4.9 我开始收到此错误

Notice: Trying to access array offset on value of type bool in /var/www/html/forms/melagot/api/class/Dashboard.PHP on line 84

我知道该错误表明该数组为空,而实际上是。想法是,当数组中有值时,我得到未定义的值错误

 public function get_student_data($id,$current_year)
    {

   $query = "SELECT * FROM form WHERE `id`=? AND `year` = ?";

    $stmt = $this->conn->prepare($query);
    $stmt->bindParam(1,$id);
    $stmt->bindParam(2,$current_year);
    $stmt->execute();

    $stmt->execute();
    
    $row = $stmt->fetch(PDO::FETCH_ASSOC);


    $this->is_army_file = $row['is_army_file'];  //this is line 84
    }

我尝试将其放置在第84行 (isset($row['is_army_file']) ? $this->is_army_file = $row['is_army_file'] : false); 我没有看到错误,但没有看到$this->is_army_file值应该在哪里,相反,我看到了未定义的变量错误

如果我将其保留原样,则会看到错误,但也会看到该值。

我尝试了$this->is_army_file =?? $row['is_army_file']; 但是我也收到一个错误。 该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)