Home > other >  ERROR: Trying to access array offset on value of type bool
ERROR: Trying to access array offset on value of type bool

Time:06-13

Code:

PHP-Version: 7.4.1

Error Line:

if($this->allianceData['ally_owner'] == $USER['id']) {

CodePudding user response:

The error means that your query don't receive a row. then he give a boolean. and you try to access the boolean. You can try this:

if($this->allianceData['ally_owner'] ?? 'default value' == $USER['id'] ?? 'default value') {

Since I don't know your entire code, I assume that you have already checked whether the user is authenticated? Either via middleware or in the code above.

CodePudding user response:

It is possible that you are trying to access a value that does not exist in your array, you can try using print_r($this->allianceData); and print_r($USER); to see how the arrangements are composed.

  •  Tags:  
  • php
  • Related