尝试访问bool类型值的数组偏移量Yii2 PHP8.2

yzuktlbb  于 2023-01-26  发布在  PHP
关注(0)|答案(1)|浏览(155)

下面的代码产生了上面提到的错误。PHP 8.2的修复方法是什么?
PHP警告- yii\base\ErrorException试图访问bool类型值的数组偏移量

In /var/www/html/atmtest/frontend/modules/atm/controllers/TwmgdtreportController.php 
at line 132

        $date = $model->tr_date;
 
        //$drID = Dailyroutine::find()->select('dr_id')->where(['dr_date' => $date, 
        //'dr_empid' => $user])->column();
 
        $post = Yii::$app->db->createCommand('SELECT * FROM dailyroutine WHERE 
        dr_date=:dr_date AND dr_empid=:dr_empid')
           ->bindValue(':dr_date', $date)
           ->bindValue(':dr_empid', $user)
           ->queryOne();
 
           $drID = $post['dr_id'];

        //print(json_encode($dr));
        //die();
icomxhvb

icomxhvb1#

我找到了解决办法

if(is_array($post)){
   $drID = $post['dr_id'];
}

相关问题