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.
Das obige ist der detaillierte Inhalt vonWarum erhalte ich in PHP 7.4 die Meldung „Versuch, auf den Array-Offset für den Wert vom Typ Bool zuzugreifen'?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!