• Hello there,

    I upgraded my website from 7.4 to 8.1. Since then I’ve been getting this error message:

    Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in […]

    This is the specified string:
    ‘count’ => count( $value ),

    $var = array(
    ‘html’ => $var . ‘Delete ‘,
    ‘count’ => count( $value ),
    ‘sortable’ => true,
    ‘limit’ => ”,
    ‘name’ => $this->parent->args[‘opt_name’] . ‘[‘ . $field[‘id’] . ‘][99999]’,
    );

    I don’t understand what’s wrong with that.

    Thanks in advance for your help,

    Jasmin

Viewing 4 replies - 1 through 4 (of 4 total)
  • This is correct. Count will throw an error in above 8.0 but a warning in 7.4.33 as this “Warning: count(): Parameter must be an array or an object that implements Countable in /home/user/scripts/code.php on line 5
    1″

    I do not think it’s in WordPress but in a plugin or theme.

    You may try to inactivate plugins one by one or change theme to find the culprit.

    Thread Starter jass78

    (@jass78)

    Thanks for your quick answer. I also think it’s a plugin issue caused by the theme. But I can’t update the theme or plugin because the theme is no longer supported. Do you have an idea how I can fix this anyway?

    What is meant by: … must be of type Countable|array … ?

    • This reply was modified 1 year, 6 months ago by jass78.

    You can count elements of an array , but you can not count strings with count() function. It seems $value is a string.

    Either, the cause is a plugin or a theme. If you think is the theme, please change theme to a WP standard theme (as Twenty Twenty or Twenty Twenty Three) and look if the error dissappears!

    I do not know what theme you use, but if your theme is not maintained any more you have to select another one.

    Moderator bcworkz

    (@bcworkz)

    If you know where the problem code is, you could patch the offending code. Examine the offending string value to decide what a proper count result should be. If the appropriate count is 1, conditionally (with is_string()) convert any string value into a single element array. If each string fragment should be counted, you could conditionally explode() the string into an array of string elements.

    TBH, switching to a better supported theme or plugin is the best option, but patching is possible for minor problems encountered during PHP updates.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP 7.4 to PHP 8.1: Uncaught TypeError’ is closed to new replies.