如何解决如何修复“尝试访问类型为空值的数组偏移量错误” - PHP 7.4
在 Xampp 上使用 PHP 7.4 处理项目时出现此错误。第 553 行是;
if ($this->data['avatar_id'] == 0)
我意识到它正在 DB_USERS 中搜索 avatar_id 但它位于 DB_ACCOUNTS 中。我认为这是导致问题的原因,但我找不到如何解决。
这些是完成代码块;
private function getData()
{
global $config;
$query = $this->getConnection()->query("SELECT * FROM " . DB_USERS . " WHERE id=" . $this->id);
if ($query->num_rows == 1)
{
$fetch = $query->fetch_array(MysqLI_ASSOC);
if (! empty($fetch['birthday']))
{
if (!preg_match('/(\-|\/)/',$fetch['birthday'])) $this->getConnection()->query("UPDATE " . DB_USERS . " SET birthday='01/01/2000' WHERE id=" . $this->id);
$fetch['birth'] = explode('-',$fetch['birthday']);
if (isset($fetch['birth'][1]))
{
$fetch['birth'] = array(
'date' => (int) $fetch['birth'][0],'month' => (int) $fetch['birth'][1],'year' => (int) $fetch['birth'][2]
);
}
else
{
$fetch['birth'] = explode('/',$fetch['birthday']);
$fetch['birth'] = array(
'date' => (int) $fetch['birth'][1],'month' => (int) $fetch['birth'][0],'year' => (int) $fetch['birth'][2]
);
}
}
if ($this->data['avatar_id'] == 0)
{
$fetch['thumbnail_url'] = $fetch['avatar_url'] = SITE_URL . '/' . $config['user_default_male_avatar'];
if (! empty($fetch['gender']))
{
if ($fetch['gender'] == "female")
{
$fetch['thumbnail_url'] = $fetch['avatar_url'] = SITE_URL . '/' . $config['user_default_female_avatar'];
}
}
}
$fetch['location'] = $fetch['current_city'];
return $fetch;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。