From a61ce4fed0eba0c1cee3b96e81be6fa89e96c9f9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 28 Jul 2019 00:03:42 -0400 Subject: [PATCH] Ensure *toArray returns an array --- src/Database/Database.php | 4 +++- src/Model/Attach.php | 4 ++-- src/Model/Item.php | 10 ++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 501d65fe76..a2e31d89b5 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1512,16 +1512,18 @@ class Database public function toArray($stmt, $do_close = true) { if (is_bool($stmt)) { - return $stmt; + return []; } $data = []; while ($row = $this->fetch($stmt)) { $data[] = $row; } + if ($do_close) { $this->close($stmt); } + return $data; } diff --git a/src/Model/Attach.php b/src/Model/Attach.php index 758d3ae831..0073a6ed3f 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -44,7 +44,7 @@ class Attach extends BaseObject * @param array $conditions Array of fields for conditions * @param array $params Array of several parameters * - * @return boolean|array + * @return array * * @throws \Exception * @see \Friendica\Database\DBA::selectToArray @@ -55,7 +55,7 @@ class Attach extends BaseObject $fields = self::getFields(); } - $r = DBA::selectToArray('attach', $fields, $conditions, $params); + return DBA::selectToArray('attach', $fields, $conditions, $params); } /** diff --git a/src/Model/Item.php b/src/Model/Item.php index c2bb6c8924..c9d3e42693 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -383,16 +383,10 @@ class Item extends BaseObject $result = self::select($fields, $condition, $params); if (is_bool($result)) { - return $result; + return []; } - $data = []; - while ($row = self::fetch($result)) { - $data[] = $row; - } - DBA::close($result); - - return $data; + return DBA::toArray($result); } /**