From 99b200868bdf1f59e2a5c0d482b501f9b71b7e67 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 10 Dec 2020 06:12:10 -0500 Subject: [PATCH] Normalize return value in Database->fetch - Address https://github.com/friendica/friendica/issues/9250#issuecomment-741857058 --- src/Database/Database.php | 7 +++---- src/Model/Item.php | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 641ebd389..0d02c4aef 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -910,13 +910,12 @@ class Database /** * Fetch a single row * - * @param mixed $stmt statement object + * @param PDOStatement|mysqli_stmt $stmt statement object * - * @return array current row + * @return array|false current row */ public function fetch($stmt) { - $stamp1 = microtime(true); $columns = []; @@ -934,7 +933,7 @@ class Database break; case self::MYSQLI: if (get_class($stmt) == 'mysqli_result') { - $columns = $stmt->fetch_assoc(); + $columns = $stmt->fetch_assoc() ?? false; break; } diff --git a/src/Model/Item.php b/src/Model/Item.php index 15ea69eeb..c67399b92 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -223,13 +223,14 @@ class Item * Fetch a single item row * * @param mixed $stmt statement object - * @return array current row + * @return array|false current row or false + * @throws \Exception */ public static function fetch($stmt) { $row = DBA::fetch($stmt); - if (is_bool($row)) { + if (!is_array($row)) { return $row; }