我刚刚将服务器的 PHP 版本升级到 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;
}
PHP 7.4 的修复是什么?
最佳答案
轻松使用 PHP ??
null coalescing operator
return $Row['Data'] ?? 'default value';
或者你可以这样使用
$Row['Data'] ??= 'default value';
return $Row['Data'];
关于php - 尝试访问 PHP 7.4 中 bool 类型值的数组偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59674903/