From b63ba5409b2d44f03a661b2245267282346e85b9 Mon Sep 17 00:00:00 2001 From: spzgy Date: Tue, 9 Jan 2024 10:49:00 +0800 Subject: [PATCH] Update BaseStringHelper.php Exception 'TypeError' with message 'count(): Argument #1 ($value) must be of type Countable|array, bool given' --- framework/helpers/BaseStringHelper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/helpers/BaseStringHelper.php b/framework/helpers/BaseStringHelper.php index 749f92f79cd..8da0cd81ab5 100644 --- a/framework/helpers/BaseStringHelper.php +++ b/framework/helpers/BaseStringHelper.php @@ -330,7 +330,11 @@ public static function explode($string, $delimiter = ',', $trim = true, $skipEmp */ public static function countWords($string) { - return count(preg_split('/\s+/u', $string, 0, PREG_SPLIT_NO_EMPTY)); + $keywords = preg_split('/\s+/u', $string, 0, PREG_SPLIT_NO_EMPTY); + if ($keywords !== false) { + return count($keywords); + } + return 0; } /**