count(): Parameter must be an array or an object that implements Countable error in project

count(): parameter must be an array or an object that implements countable stackoverflow
count(): parameter must be an array or an object that implements countable laravel
parameter must be an array or an object that implements countable - magento 2
phpmyadmin count(): parameter must be an array or an object that implements countable
sizeof(): parameter must be an array or an object that implements countable
sizeof(): parameter must be an array or an object that implements countable pnp4nagios
count(): parameter must be an array or an object that implements countable yii2
guzzle parameter must be an array or an object that implements countable

I'm currently working on a laravel project and I'm following a course. Everything was going just fine, untill I had to add "eloquent-sluggable" to my project. That package works just fine, but now I get the following error in my project:

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

I'm using that count() function in my view:

@if($comments->count() > 0)
   @forech($comments as $comment)
     //displaying single comment data
  @endforeach
@endif

Now my question is, why does that error gets shown now. Could it be because I did "composer update" in my project and it updated my PHP version to 7.2, and there is a count() problem in that version? I'm guessing the ">=" sign changed my PHP version. My current laravel project configuration:

"php": ">=5.5.9",
    "laravel/framework": "5.2.*"

But when I run "php -v" in my project, it shows that my PHP version is 7.2 now. Is there a way I could downgrade my PHP version without loosing my project files? Any help appreciated.

What you are trying to do could be solved with https://laravel.com/docs/5.6/collections#method-count

This would turn your

@if(count($comment)>0)
   //displaying comments
@endif

to

@if($comment->count() > 0)
//displaying comments
@endif

count(): Parameter must be an array or an object that , count(): Parameter must be an array or an object that implements it could be a core bug https://www.drupal.org/project/drupal/issues/2928846  PHP 7.2 Warning: count(): Parameter must be an array or an object that implements Countable in taxonomy_form_term_submit() in taxonomy.admin.inc

You can try this one

$comment = comment::get()->all();

@if(count($comment)>0)
  //displaying comments
@endif

PHP warning “Parameter must be an array or an object that , Q A Bug? yes New Feature? no Version 6.2.1 Actual Behavior I get an together to host and review code, manage projects, and build software together. count(): Parameter must be an array or an object that implements Countable #1973 $​this->handles should be an array or implement Countable. In development it works fine. But in production it gives me this error: count(): Parameter must be an array or an object that implements Countable in Builder.php (line 936) as you can see in this pic: Any idea what is the reason behind this? and how to fix?

So first of all, you shouldn't use in your controller:

$comment = Comment::all();

but

$comments = Comment::all();

and pass this to view as

return view('some_view', compact('comments'));

As it's collection you should use plural variable name to avoid confusion.

Now in your view you should use:

@if ($comments->count())
   @foreach ($comments as $comment)
      // here you display single comment data for example {{ $comment->text }}
   @endforeach
@endif

[PHP7] Warning: count(): Parameter must be an array or an object , I have the same error 'Warning: count(): Parameter must be an array or an object that implements Countable in' /wp-includes/post-template.php on line 310. This error occurs in php\laravel due to various reasons. If you are working in the development mode then ->wheres) ? count($query->wheres) : 0;

Here you can do a few things:-

  1. You can downgrade your PHP version.
  2. You can update your syntax while executing the query:-

Change from this

$comment = Comment::get();

to this

$comment = Comment::get()->toArray();

[PHP 7.2] My fix for «Warning: count(): Parameter must be an array , count(): Parameter must be an array or an object that implements Countable Table.php:789. Closed (works as designed). Project: File_entity module cause an INFINITY ERROR FOR UPDATE DRUPAL 7 (latest version core). [16:26:31] [Server thread/CRITICAL]: Unhandled exception executing command 'f create test' in f: count(): Parameter must be an array or an object that implements Countable [16:26:31] [Server thread/CRITICAL]: ErrorException: "count(): Parameter must be an array or an object that implements Countable" (EXCEPTION) in "plugins/GuildsRPG-master/src

The only way I could get around this, is by editing error Line 1185 in 'vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php' with:

$originalWhereCount = is_array($query->wheres) ? count($query->wheres) : 0;

I don't know if this is bad for future project, but this was the only way I could get my project to work.

Warning: count(): Parameter must be an array or an object that , [PHP7] Warning: count(): Parameter must be an array or an object that implements Countable in PHP 7.2. Closed (duplicate). Project: Drupal core. Version: looks like it is good, what would we need from#7 several errors? Saw the following after upgrading two of my sites to file_entity 2.27 using drush: Project file_entity was updated successfully. Installed version is now 7.x-2.27. count(): Parameter must be an array or an object that implements Countable Table.php:789 [warning] File_entity 7227 Remove deprecated views_plugin_access_menu plugin.

php 7.2 count(): Parameter must be an array or an object that , Warning: count(): Parameter must be an array or an object that implements Countable in lib/internal/Magento/Framework/View/Design/Theme/ThemeList.​php on  count() parameter must be an array or an object that implements countable in laravel

Thanks Warning : count(): Parameter must be an array or an object that Warning: count(): Parameter must be an array or an object that implements I'm getting this error message when clicking the FILES link inside my Projects page. Since PHP 7.2 count() yields a warning on invalid countable types  I found this bug / would like to have this new functionality When generating the PDF I get the following error: PHP Warning: count(): Parameter must be an array or an object that implements Countab

However, in production I'm receiving the error count(): Parameter must be an array or an object that implements Countable. Here's my query. #4155189 count(): Parameter must be an array or an object that implements Countable. Submitted by PocketMine-MP 3.12.0

Comments
  • what is "$comment"?
  • You are passing object instead of array. Count( ) function only count the array. First of all convert it to array.
  • I'm putting all the comments in that variable in my controller: $comment = Comment::all();
  • I know, I misspelled it here on this question. I'm using it that way in the project
  • So if you used code I showed, you are still getting error? You are really using count() on $comments and not on $comment ?. Please update your question with code you really use
  • Updated question, still getting the same error. Do I have to change the code for every count that I have in my project now?
  • @zlatangoralija Not really. How are you getting your comments? Do you run just $comments = Comment::all(); in your controller or maybe you are doing this in some different way?
  • I just run $comments = Comment::all(); , but I tried some suggestions above, still getting the same error...
  • This is totally bad practice as you are making changes in the core file.
  • I know, I'll try no to do this in future projects. I just wanted to make it work by any means...
  • Sorry, but when you will update your composer, the custom code which you have done will be overwritten.