Skip to content

Commit

Permalink
Update BaseStringHelper.php
Browse files Browse the repository at this point in the history
Exception 'TypeError' with message 'count(): Argument yiisoft#1 ($value) must be of type Countable|array, bool given'
  • Loading branch information
spzgy authored Jan 9, 2024
1 parent b46e267 commit b63ba54
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion framework/helpers/BaseStringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit b63ba54

Please sign in to comment.