Phpmyadmin – Count(): Parameter Must Be An Array Or An Object That Implements Countable

In PHP, starting from version 7.2, the count() function raises a warning when the parameter is not an array or an object that implements the Countable interface.

To fix the "Parameter must be an array or an object that implements Countable" error in phpMyAdmin, you can follow these steps:

  1. Check the version of PHP that you are using. You can do this by creating a PHP file with the following code and accessing it through a web browser:
<?php
phpinfo();
?>

Look for the PHP version in the output.

  1. If you are using PHP 7.2 or above, you can modify the code to avoid the warning. Open the file where the count() function is used and find the line that triggers the warning. It might look something like this:
$count = count($items);
  1. Change the code to explicitly check if the parameter is null or an array before using the count() function. Here’s an example:
$count = is_array($items) ? count($items) : 0;

This code first checks if $items is an array using the is_array() function. If it is, the count() function is called; otherwise, the count is set to 0.

By making this modification, you avoid the warning and provide a default value for cases when $items is not an array.

  1. Save the file and refresh the page where the error occurred. The warning should no longer appear.

Remember to review the code and ensure that using count() on $items makes logical sense in your specific context.

About the Author Rex

I'm a passionate tech blogger with an insatiable love for programming! From my early days tinkering with code, I've delved into web dev, mobile apps, and AI. Sharing insights and tutorials with the world is my joy, connecting me to a global community of like-minded tech enthusiasts. Python holds a special place in my heart, but I embrace all challenges. Constantly learning, I attend tech conferences, contribute to open-source projects, and engage in code review sessions. My ultimate goal is to inspire the next generation of developers and contribute positively to the ever-evolving tech landscape. Let's code together!