diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 48dd3cd68ea5f056341274da2938087e35e998fb..69d93797ba04604852b844b4761aca4a27374597 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -923,7 +923,8 @@ class Share extends \OC\Share\Constants {
 		} else {
 			$fileDependent = false;
 			$root = '';
-			if ($includeCollections && !isset($item) && ($collectionTypes = self::getCollectionItemTypes($itemType))) {
+			$collectionTypes = self::getCollectionItemTypes($itemType);
+			if ($includeCollections && !isset($item) && $collectionTypes) {
 				// If includeCollections is true, find collections of this item type, e.g. a music album contains songs
 				if (!in_array($itemType, $collectionTypes)) {
 					$itemTypes = array_merge(array($itemType), $collectionTypes);
@@ -986,7 +987,8 @@ class Share extends \OC\Share\Constants {
 			}
 		}
 		if (isset($item)) {
-			if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) {
+			$collectionTypes = self::getCollectionItemTypes($itemType);
+			if ($includeCollections && $collectionTypes) {
 				$where .= ' AND (';
 			} else {
 				$where .= ' AND';