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.
以上是為什麼我在 PHP 7.4 中收到「嘗試存取 Bool 類型值的陣列偏移量」?的詳細內容。更多資訊請關注PHP中文網其他相關文章!