Support » Fixing WordPress » ERROR: Warning: count(): Parameter must be an array or an object that implements

  • WordPress 5.3
    Running PHP version: 7.2.25

    Hi,

    i moved a site to another server for a friend,
    encountering following issue when trying to rename a menu item. was not able to find a specific fix:

    Warning: count(): Parameter must be an array or an object that implements Countable,

    referring to the second line of this code:

    foreach( $_POST as $key => $arr ){
    $count+= count( $arr );
    }

    would be grateful if someone had a hint, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey @tom7777777,
    I think $arr in some cases is empty and when you call count function on a noncountable variable you will see that message.
    In this case, you can some simple validation like

    if (is_array($arr)) {
    $count+= count( $arr );
    }
    

    I hope that helps.

    tom7777777

    (@tom7777777)

    That worked, thanks a lot @sygnoos

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.