S
S
spido2022-04-22 00:52:46
PHP
spido, 2022-04-22 00:52:46

How to fix Trying to access array offset on value of type null?

Greetings!
After upgrading to PHP 7.4, a bug appeared that cannot be fixed.
If the $favorites_info value does not exist, it throws an error Trying to access array offset on value of type
null

$fav_id = $goods_id;
        $favorites_model = model('favorites');
        //Вы уже добавили этот товар в избранное
        $favorites_info = $favorites_model->getOneFavorites(array(
            'fav_id' => "$fav_id",
            'fav_type' => 'goods',
            'member_id' => session('member_id')
        ));

    //$favorites_info = $favorites_info ?? ''; //я добавил этот код, но выдает ошибку Illegal string offset 'fav_id'

    View::assign('favorites_info', $favorites_info);

In the template it looks like this:
{$favorites_info.fav_id}
I added a check $favorites_info = $favorites_info ?? ''; but now it gives an error Illegal string offset 'fav_id'
Can you tell me how to fix it?
Thanks in advance for those who respond!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question