Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. PHP Fatal error: Uncaught TypeError: count()

PHP Fatal error: Uncaught TypeError: count()

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpphpdatabasemysqldata-structures
3 Posts 2 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aruna KN
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • A Aruna KN

      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

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      Replacing count($row[0]); with strlen($row[0]); should do it.

      A 1 Reply Last reply
      0
      • G Graham Breach

        Replacing count($row[0]); with strlen($row[0]); should do it.

        A Offline
        A Offline
        Aruna KN
        wrote on last edited by
        #3

        Yes it worked!! Thank you!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups