[1/2] fix php 7.4 warnings

Message ID 20200212201638.3051647-2-eschwartz@archlinux.org
State New
Headers show
Series
  • php warning fixes
Related show

Commit Message

Eli Schwartz Feb. 12, 2020, 8:16 p.m. UTC
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>
---
 web/lib/aur.inc.php      | 28 +++++++++++++++++++++-------
 web/lib/pkgfuncs.inc.php |  4 +++-
 2 files changed, 24 insertions(+), 8 deletions(-)

Patch

diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index e9530fc0..dbcc23a4 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -197,7 +197,9 @@  function username_from_id($id) {
 	}
 
 	$row = $result->fetch(PDO::FETCH_NUM);
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
@@ -222,7 +224,9 @@  function username_from_sid($sid="") {
 	}
 	$row = $result->fetch(PDO::FETCH_NUM);
 
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
@@ -339,7 +343,9 @@  function email_from_sid($sid="") {
 	}
 	$row = $result->fetch(PDO::FETCH_NUM);
 
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
@@ -365,7 +371,9 @@  function account_from_sid($sid="") {
 	}
 	$row = $result->fetch(PDO::FETCH_NUM);
 
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
@@ -390,7 +398,9 @@  function uid_from_sid($sid="") {
 	}
 	$row = $result->fetch(PDO::FETCH_NUM);
 
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
@@ -512,7 +522,9 @@  function uid_from_username($username) {
 	}
 
 	$row = $result->fetch(PDO::FETCH_NUM);
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
@@ -546,7 +558,9 @@  function uid_from_email($email) {
 	}
 
 	$row = $result->fetch(PDO::FETCH_NUM);
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index a4cd17ac..8c915711 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -147,7 +147,9 @@  function pkg_from_name($name="") {
 		return;
 	}
 	$row = $result->fetch(PDO::FETCH_NUM);
-	return $row[0];
+	if ($row) {
+		return $row[0];
+	}
 }
 
 /**