From 93a56b6fea65fcdb9c26518c12c98cf2ada5fb1e Mon Sep 17 00:00:00 2001 From: Craig Anderson Date: Thu, 12 Jul 2018 09:56:45 -0400 Subject: [PATCH] getField() and getSnippets() now check if $fieldName is an array before counting elements. Otherwise, if we try to use count() when $fieldName is not a countable entity, count() will throw an exception in PHP-7.2 or higher. --- src/OpenSearchServer/Response/Result.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/OpenSearchServer/Response/Result.php b/src/OpenSearchServer/Response/Result.php index 933b45f..44aeed5 100644 --- a/src/OpenSearchServer/Response/Result.php +++ b/src/OpenSearchServer/Response/Result.php @@ -63,8 +63,10 @@ public function getCollapsedCount() { * Default value: true. */ public function getField($fieldName, $returnFirstValueOnly = true) { - if(!empty($this->fields[$fieldName]) && count($this->fields[$fieldName] > 0)) { - return ($returnFirstValueOnly) ? $this->fields[$fieldName][0] : $this->fields[$fieldName]; + if(!empty($this->fields[$fieldName]) ) { + if (is_array($this->fields[$fieldName]) && count($this->fields[$fieldName]) > 0) { + return ($returnFirstValueOnly) ? $this->fields[$fieldName][0] : $this->fields[$fieldName]; + } } } @@ -76,8 +78,10 @@ public function getField($fieldName, $returnFirstValueOnly = true) { * Default value: true. */ public function getSnippet($fieldName, $returnFirstValueOnly = true) { - if(!empty($this->snippets[$fieldName]) && count($this->snippets[$fieldName] > 0)) { - return ($returnFirstValueOnly) ? $this->snippets[$fieldName][0] : $this->snippets[$fieldName]; + if(!empty($this->snippets[$fieldName]) && is_array($this->snippets[$fieldName])) { + if (count($this->snippets[$fieldName]) > 0) { + return ($returnFirstValueOnly) ? $this->snippets[$fieldName][0] : $this->snippets[$fieldName]; + } } } @@ -112,4 +116,4 @@ public function getHighlightedSnippets() { public function isHighlightedSnippets($fieldname) { return in_array($fieldname, $this->highlightedSnippets); } -} \ No newline at end of file +}