陷入錯誤:PHP 7.4 中布爾值的數組偏移訪問
查詢:
升級到PHP 7.4.1 後,出現下列錯誤:
Notice: Trying to access array offset on value of type bool in
此程式碼區塊內:
public static function read($id) { $Row = MySQL::query("SELECT `Data` FROM `cb_sessions` WHERE `SessionID` = '$id'", TRUE); # http://php.net/manual/en/function.session-start.php#120589 //check to see if $session_data is null before returning (CRITICAL) if(is_null($Row['Data'])) { $session_data = ''; } else { $session_data = $Row['Data']; } return $session_data; }
解:
解決方案:return $Row['Data'] ?? 'default value';
$Row['Data'] ??= 'default value'; return $Row['Data'];
以上是為什麼我在 PHP 7.4 中收到「錯誤陷阱:布林值上的陣列偏移存取」?的詳細內容。更多資訊請關注PHP中文網其他相關文章!