Fix PHP 7.4 warnings

If a db query returned NULL instead of an array, then accessing $row[0]
now throws a warning. The undocumented behavior of evaluating to NULL
is maintained, and we want to return NULL anyway, so add a check for the
value and fall back on the default function return type.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Eli Schwartz 2020-02-12 15:16:37 -05:00 committed by Lukas Fleischer
parent 65c98d1216
commit 5ca1e271f9
2 changed files with 24 additions and 8 deletions

View file

@ -197,8 +197,10 @@ function username_from_id($id) {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Determine the user's username in the database using a session ID
@ -222,8 +224,10 @@ function username_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Format a user name for inclusion in HTML data
@ -339,8 +343,10 @@ function email_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Determine the user's account type in the database using a session ID
@ -365,8 +371,10 @@ function account_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Determine the user's ID in the database using a session ID
@ -390,8 +398,10 @@ function uid_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Common AUR header displayed on all pages
@ -512,8 +522,10 @@ function uid_from_username($username) {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Determine the user's ID in the database using a username or email address
@ -546,8 +558,10 @@ function uid_from_email($email) {
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Generate clean url with edited/added user values

View file

@ -147,8 +147,10 @@ function pkg_from_name($name="") {
return;
}
$row = $result->fetch(PDO::FETCH_NUM);
if ($row) {
return $row[0];
}
}
/**
* Get licenses for a specific package