close

[Solved] Notice: Trying to access array offset on value of type bool

Hello Guys, How are you all? Hope You all Are Fine. Today I just updated php to 7.4 and now I am facing following error Notice: Trying to access array offset on value of type bool in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Notice: Trying to access array offset on value of type bool Error Occurs ?

Today I just updated php to 7.4 and now I am facing following error.

Notice: Trying to access array offset on value of type bool

Here is code that I am trying to execute.

    if(is_null($userData['userList'])) { // here I am facing issue
        //some stuff
    } else {
        //some stuff
    }

How To Solve Notice: Trying to access array offset on value of type bool Error ?

  1. How To Solve Notice: Trying to access array offset on value of type bool Error ?

    To Solve Notice: Trying to access array offset on value of type bool Error Just use Use Null Coalescing Operator like this $userData['userList'] ??= 'your default value'; Second solution is Just Use multiple if condition like given below code.

  2. Notice: Trying to access array offset on value of type bool

    To Solve Notice: Trying to access array offset on value of type bool Error Just use Use Null Coalescing Operator like this $userData['userList'] ??= 'your default value'; Second solution is Just Use multiple if condition like given below code.

Solution 1: Use Null Coalescing Operator

return $userData['userList'] ?? 'your default value';

Or you can use like this

$userData['userList'] ??= 'your default value';
return $userList['userList'];

Solution 2: Use if condition like this

Just Use multiple if condition like this.

if($userData){

   if($userData['userList']){
     // your stuff
   }else{
    // your stuff
   }

}

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment