PHP Fatal error: Uncaught TypeError: count()
-
My code is working on PHP 7.4 and now I'm testing it with PHP 8 and getting following error_log:
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in D:\localhost\htdocs\chat\dtc\engine\mysql\board_alerter.php:13
board_alerter.php is as given below:
".mysqli_error($conn));
if (mysqli_num_rows($m_result))
list($new_board_messages) = mysqli_fetch_array($m_result, MYSQLI_NUM);
if (!isset($new_board_messages)) $new_board_messages = "0";
mysqli_free_result($m_result);$m_result = mysqli_query($conn,"select concat(subject,body) from ".$mysql_table_prefix."board where user_id=$is_regist") or die("database error: cannot retrieve mail-messages
".mysqli_error($conn));
$total = 0;
while ($row = mysqli_fetch_array($m_result, MYSQLI_NUM))
$total += count($row[0]);$percentage = round($total / $max_mailbox_size *100);
mysqli_free_result($m_result);
?>Please suggest me a fix
-
My code is working on PHP 7.4 and now I'm testing it with PHP 8 and getting following error_log:
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in D:\localhost\htdocs\chat\dtc\engine\mysql\board_alerter.php:13
board_alerter.php is as given below:
".mysqli_error($conn));
if (mysqli_num_rows($m_result))
list($new_board_messages) = mysqli_fetch_array($m_result, MYSQLI_NUM);
if (!isset($new_board_messages)) $new_board_messages = "0";
mysqli_free_result($m_result);$m_result = mysqli_query($conn,"select concat(subject,body) from ".$mysql_table_prefix."board where user_id=$is_regist") or die("database error: cannot retrieve mail-messages
".mysqli_error($conn));
$total = 0;
while ($row = mysqli_fetch_array($m_result, MYSQLI_NUM))
$total += count($row[0]);$percentage = round($total / $max_mailbox_size *100);
mysqli_free_result($m_result);
?>Please suggest me a fix
Replacing
count($row[0]);
withstrlen($row[0]);
should do it. -
Replacing
count($row[0]);
withstrlen($row[0]);
should do it.