New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7.2 issues: count(): Parameter must be an array or an object that implements Countable #1767

Closed
necrogami opened this Issue Dec 16, 2017 · 39 comments

Comments

Projects
None yet
@necrogami
Copy link

necrogami commented Dec 16, 2017

ErrorException in Builder.php line 1231:
count(): Parameter must be an array or an object that implements Countable
in Builder.php line 1231
at HandleExceptions->handleError('2', 'count(): Parameter must be an array or an object that implements Countable', '/var/www/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php', '1231', array('scope' => object(Closure), 'parameters' => array(object(Builder)), 'query' => object(Builder)))
at count(null) in Builder.php line 1231
at Builder->callScope(object(Closure)) in Builder.php line 1262
at Builder->applyScopes() in Builder.php line 325
at Builder->get() in /var/www/app/app/Http/Middleware/StartupCheck.php line 208
        // Check data has been cached
        $cachedTables = unserialize(CACHED_TABLES);
        if (Input::has('clear_cache')) {
            Session::flash('message', 'Cache cleared');
        }
        foreach ($cachedTables as $name => $class) {
            if (Input::has('clear_cache') || ! Cache::has($name)) {
                // check that the table exists in case the migration is pending
                if (! Schema::hasTable((new $class())->getTable())) {
                    continue;
                }
                if ($name == 'paymentTerms') {
                    $orderBy = 'num_days';
                } elseif ($name == 'fonts') {
                    $orderBy = 'sort_order';
                } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
                    $orderBy = 'name';
                } else {
                    $orderBy = 'id';
                }
                $tableData = $class::orderBy($orderBy)->get(); // This line right here is the error
                if (count($tableData)) {
                    Cache::forever($name, $tableData);
                }
            }
        }

Clean install this happens immediately after setup is finished.
Database tables exist.
Clear compiled does not fix.
Latest download as of 8pm Eastern on 12/05/2017

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Dec 16, 2017

Which version of PHP are you using, it may be an issue with PHP 7.2.

hillelcoren added a commit that referenced this issue Dec 16, 2017

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Dec 16, 2017

I've checked in a fix for the issue but I imagine there will be more problems like it with PHP 7.2.

@necrogami

This comment has been minimized.

Copy link

necrogami commented Dec 16, 2017

@necrogami

This comment has been minimized.

Copy link

necrogami commented Dec 18, 2017

This is not resolved with the change of code.

I have reset my install.
Dropped / created database
Deleted directory and cloned git repo and switched to develop branch
ran composer and chmod/chown folders
loaded page and ran wizard.

Still getting the same error even after the change.

@necrogami

This comment has been minimized.

Copy link

necrogami commented Dec 18, 2017

I added a small block of code around the problem.

dump($class);
$tableData = $class::orderBy($orderBy)->get();
dump($tableData);
if ($tableData->count()) {
    Cache::forever($name, $tableData);
}

This is the result

"App\Models\Currency"
Collection {#1653 ▼
  #items: array:69 [▶]
}
"App\Models\Size"
Collection {#6883 ▼
  #items: array:6 [▶]
}
"App\Models\Industry"
Collection {#7345 ▼
  #items: array:33 [▶]
}
"App\Models\Timezone"
Collection {#9533 ▼
  #items: array:113 [▶]
}
"App\Models\DateFormat"
Collection {#14298 ▼
  #items: array:13 [▶]
}
"App\Models\DatetimeFormat"
Collection {#15230 ▼
  #items: array:13 [▶]
}
"App\Models\Language"
Collection {#16136 ▼
  #items: array:26 [▶]
}
"App\Models\PaymentTerm"
Whoops, 

So it's getting through caching everything and then when it gets to payment terms it chokes.

@hillelcoren hillelcoren added the bug label Dec 18, 2017

@hillelcoren hillelcoren changed the title count(): Parameter must be an array or an object that implements Countable PHP 7.2 issues: count(): Parameter must be an array or an object that implements Countable Dec 18, 2017

@sandersr

This comment has been minimized.

Copy link

sandersr commented Dec 19, 2017

hillelcoren added a commit that referenced this issue Jan 16, 2018

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Jan 16, 2018

I've fixed the count() issues in the code however the app won't support PHP 7.2 until we upgrade to Laravel 5.4.

@zishanj

This comment has been minimized.

Copy link

zishanj commented Jan 19, 2018

After completing the setup, I am receiving this error in log:

/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php [Line 1231] => count(): Parameter must be an array or an object that implements Countable {"context":"PHP","user_id":0,"account_id":0,"user_name":"","method":"GET","url":"http://localhost:8080/update","previous":"http://localhost:8080/setup","user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5","ip":"::1","count":1,"is_console":"no","is_api":"no","db_server":"mysql"} []

After investigating I came to know that only Laravel 5.5 or higher is supported by PHP 7.2. Unfortunately my hosting company have PHP 7.2 and can't use invoice on it. :(

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Jan 20, 2018

My web hosts enable selecting the version of PHP to use.

@zishanj

This comment has been minimized.

Copy link

zishanj commented Jan 21, 2018

Instead of using "php": ">=7.0.0" in composer use "php": "~7.1.0" to install only supported PHP version 7.1.x.

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Jan 21, 2018

PHP 7.0 is also supported

@zishanj

This comment has been minimized.

Copy link

zishanj commented Jan 21, 2018

problem is with >= operators which install latest PHP version above 7.0 which is 7.2.1. If you use ~ instead then it will install only within a specific range like 7.0.x or 7.1.x whichever version you mention.

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Jan 21, 2018

Thanks for the suggestion!

hillelcoren added a commit that referenced this issue Jan 21, 2018

@DASPRiD

This comment has been minimized.

Copy link

DASPRiD commented Jan 31, 2018

@hillelcoren any time frame for when PHP 7.2 support will be added?

@turbo124

This comment has been minimized.

Copy link
Member

turbo124 commented Jan 31, 2018

@DASPRiD along with upgrading to Laravel 5.4, there are other dependent packages which are not PHP 7.2 ready so it may be some time before 7.2 is supported.

@turbo124 turbo124 added compatibility and removed bug labels Jan 31, 2018

@user00265

This comment has been minimized.

Copy link

user00265 commented Feb 9, 2018

count() and sizeof() are two functions affected.

@garygreen

This comment has been minimized.

Copy link

garygreen commented Feb 23, 2018

Any news on this? Can't use ninja on PHP 7.2.... saaaaaay wattt! 😄

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Feb 23, 2018

It should hopefully be supported with our next major release (v4.3) in about 4 to 6 weeks.

@garygreen

This comment has been minimized.

Copy link

garygreen commented Feb 23, 2018

It should hopefully be supported with our next major release (v4.3) in about 4 to 6 weeks.

Oh wow, that long? Is there no way to hot patch the bugs just so it supports 7.2? Waiting nearly 2 months seems a long time, especially when 7.2 was released last Nov...

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Feb 24, 2018

Supporting a new PHP version in our code is easy, supporting it in all of the libraries we use is hard.

PHP 7.2 requires upgrading our app from Laravel 5.3 to 5.4, that isn't possible with a 'hot patch'.

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Feb 26, 2018

The changes have been checked into the develop branch.

If anyone wants to try it out it would be helpful.

@hillelcoren hillelcoren added the fixed label Feb 26, 2018

@lifehome

This comment has been minimized.

Copy link

lifehome commented Mar 5, 2018

Hello there, I am running into this issue by using v4.2.0 standalone zip, may I know is there a newer version available for now?

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Mar 5, 2018

To use the zip you'll need to wait for the v4.3 release.

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Mar 27, 2018

PHP 7.2 support is now available on the master branch.

@hillelcoren

This comment has been minimized.

Copy link
Member

hillelcoren commented Apr 8, 2018

v4.3 with support for PHP 7.2 has been released.

@deskmonoar

This comment has been minimized.

Copy link

deskmonoar commented May 17, 2018

I Solve this in Laravel 5.6

// in controller

public function index()
{
$todos = Todo::all();
return view('todos.index')->with(['todos' => $todos]);

}

// in view page

@if(count($todos) > 0)
  @foreach($todos as $todo)
    <div class="well">
      <h3>{{$todo->text}}</h3>
      <span class="label label-danger">{{$todo->due}}</span>
    </div>
  @endforeach
@endif
@otaviopires

This comment has been minimized.

Copy link

otaviopires commented Jul 16, 2018

ran thought the same erro laravel 5.6.26 and php v7.2.7

@Kronos35

This comment has been minimized.

Copy link

Kronos35 commented Aug 4, 2018

@otaviopires did you find a work around for it?

@otaviopires

This comment has been minimized.

Copy link

otaviopires commented Aug 6, 2018

I changed to php 7.1

@james2doyle

This comment has been minimized.

Copy link

james2doyle commented Aug 19, 2018

Since I was using PHP 7.2 locally but 5.6 on the production server, I fixed this by casting an array on the offending line.

So, this line:

count($query->wheres)

Became:

count((array)$query->wheres)

I didn’t mind modifying the package as it is only for local development and it was easier than switching PHP versions.

@dianajoan

This comment has been minimized.

Copy link

dianajoan commented Oct 30, 2018

@james2doyle i followed your steps, thanks,
it worked for me.
i was able to login
screenshot from 2018-10-30 19-28-46

@osdeibi

This comment has been minimized.

Copy link

osdeibi commented Oct 30, 2018

Since I was using PHP 7.2 locally but 5.6 on the production server, I fixed this by casting an array on the offending line.

So, this line:

count($query->wheres)

Became:

count((array)$query->wheres)

I didn’t mind modifying the package as it is only for local development and it was easier than switching PHP versions.

This works for me

@quantumleap33

This comment has been minimized.

Copy link

quantumleap33 commented Nov 15, 2018

Since I was using PHP 7.2 locally but 5.6 on the production server, I fixed this by casting an array on the offending line.

So, this line:

count($query->wheres)

Became:

count((array)$query->wheres)

I didn’t mind modifying the package as it is only for local development and it was easier than switching PHP versions.

Worked for me too, thanks!

@Siknoidas

This comment has been minimized.

Copy link

Siknoidas commented Dec 12, 2018

Since I was using PHP 7.2 locally but 5.6 on the production server, I fixed this by casting an array on the offending line.

So, this line:

count($query->wheres)

Became:

count((array)$query->wheres)

I didn’t mind modifying the package as it is only for local development and it was easier than switching PHP versions.

Thanks worked for me too! Problem was old Laravel and php version 7.2.
P.S. first my comment :)

@Extarys

This comment has been minimized.

Copy link

Extarys commented Dec 18, 2018

Can someone point out which file should I modify for php 7.2?

@osdeibi

This comment has been minimized.

Copy link

osdeibi commented Dec 18, 2018

Can someone point out which file should I modify for php 7.2?

you can use the search tool to find where is the "count($query->wheres)" and do the replace.
I'm not right now behind a computer to tell you the specific file, but this will help you.

@Extarys

This comment has been minimized.

Copy link

Extarys commented Dec 18, 2018

Thanks, I was in an ssh connection, I'll download locally and search for it then. Thanks!

@Stenfrank

This comment has been minimized.

Copy link

Stenfrank commented Jan 9, 2019

Como estaba usando PHP 7.2 localmente pero 5.6 en el servidor de producción, lo arreglé colocando una matriz en la línea ofensiva.

Por lo tanto, esta línea:

count($query->wheres)

Convirtió:

count((array)$query->wheres)

No me importó modificar el paquete, ya que es solo para el desarrollo local y fue más fácil que cambiar las versiones de PHP.

Solucionado por el momento

@singhateh

This comment has been minimized.

Copy link

singhateh commented Jan 13, 2019

@james2doyle your command helps a lot and thank you so much i have been struggling for this small problem since in the morning and once again thank you so much. it's working fine for me now and thanks to you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment