Home >Backend Development >PHP Tutorial >Why Am I Getting \'Trying to Access Array Offset on Value of Type Bool\' in PHP 7.4?
Array Access Error in PHP 7.4: "Trying to Access Array Offset on Value of Type Bool"
When upgrading to PHP 7.4, you may encounter the error "Trying to access array offset on value of type bool." This can occur due to accessing an array key that contains a boolean value.
Consider the following example code:
public static function read($id) { $Row = MySQL::query("SELECT `Data` FROM `cb_sessions` WHERE `SessionID` = '$id'", TRUE); // Check for null value before accessing Data key $session_data = $Row['Data'] ?? ''; return $session_data; }
In this case, the $Row['Data'] key may contain a boolean value, which will cause the error in PHP 7.4. To resolve this, you can use the null coalescing operator (??) to conditionally assign a default value if the value is null. Alternatively, you can use the null coalesce assignment operator (??=) to assign a default value and check for nullity.
The above is the detailed content of Why Am I Getting \'Trying to Access Array Offset on Value of Type Bool\' in PHP 7.4?. For more information, please follow other related articles on the PHP Chinese website!