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

Related searches

When i add select form field in elementor and try to save i get an error message.The code below is where the issue is

private function maybe_truncate_log() {
    /** @var Log_Item[] $log */
    $log = $this->get_log();

    if ( Log_Item::MAX_LOG_ENTRIES < count( $log ) ) {
        $log = array_slice( $log, -Log_Item::MAX_LOG_ENTRIES );
    }

    return $log;
}

This error occur when your array $log sometime may be empty or null so you should a check before using it in count function. check code below.

if(!empty($log)){
   if ( Log_Item::MAX_LOG_ENTRIES < count( $log ) ) {
        $log = array_slice( $log, -Log_Item::MAX_LOG_ENTRIES );
    }
}

PHP 7.2, PHP 7.2 - Warning: count(): Parameter must be an array or an object that implements Countable [closed] � php php-7.2. Closed. This question� Warning: count(): Parameter must be an array or an object that implements Countable can be fixed by using a small php function is_array()

$log = $this->get_log();
$log = json_decode(json_encode($log), true);

This will transform $log from object to array.

[PHP 7.2] My fix for �Warning: count(): Parameter must be an array , Warning: count(): Parameter must be an array or an object that implements Countable in lib/internal/Magento/Framework/View/Design/Theme/ThemeList. php on� I've been shown a warning message at my add product page post upgrading PHP into 7.2 version, it says "Warning:** count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\E-comm\register_page\add_product.php on line 281

Your question is self explanatory, to make it straight here's the code that should work:

private function maybe_truncate_log() {
    /** @var Log_Item[] $log */
    $log = $this->get_log();
    if(is_array($log)){
       if ( Log_Item::MAX_LOG_ENTRIES < count( $log ) ) {
         $log = array_slice( $log, -Log_Item::MAX_LOG_ENTRIES );
       }
    }

    return $log;
}

PHP Warning: count(): Parameter must be an array or an object , PHP Warning: count(): Parameter must be an array or an object… Warning: count(): Parameter must be an array or an object that implements Countable This is just a PHP warning, purging should be working as normal. Error: Warning: count(): Parameter must be an array or an object that implements Countable in C:\xam Publicado por BlowDix ( 2 intervenciones ) el 27/08/2020 21:59:10

Fix for PHP >=7.2 warning, Fix for PHP >=7.2 warning - count(): Parameter must be an array or an object that implements Countable. As of PHP 7.2 count() will now issue a warning if the variable passed is not an array or countable object. Attached is a patch that fixes this warning in admin_theme. Hi i have fixed the problem class-wcal-abandoned-orders-table.php as suggested chetnapatel (@chetnapatel), I have fix in the same way class-wcal-recover-orders-table row 213

PHP 7.2: Warning: count(): Parameter must be an array or an object , 'Warning: count(): Parameter must be an array or an object that implements Countable in wp-includes/post-template.php on line 284'. Using PHP� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

#4495818 count(): Parameter must be an array or an object that implements Countable. Submitted by PocketMine-MP 3.15.0

Comments
  • the error seems clear, what do you think $log is ? you can check with var_dump($log)
  • get_log() isn't returning what it's supposed to be. You need to check that function and see what's going wrong there. If you add some other code to only check the count if $log is countable, you may end up covering up a problem rather than solving it.
  • Hi thanks. I tried this fix but I still get the error and can't save the form page
  • When i use radio buttons I'm able to save the page. But when it's the select/dropdown field the error comes up
  • Please add form html in your question?