Skip to content
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

count generate waring in PHP 7 if there array is null #459

Closed
yourchoice opened this issue Jul 9, 2018 · 2 comments
Closed

count generate waring in PHP 7 if there array is null #459

yourchoice opened this issue Jul 9, 2018 · 2 comments

Comments

@yourchoice
Copy link

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

{$c = $var|count}

@tchalvak
Copy link

tchalvak commented Aug 11, 2018

This is related to the php 7.x changes themselves, where count() can no longer be passed nulls. Unfortunately the only workaround that I am aware of is to also add a !empty($var) as well, or ensure the var is always countable, even if it is an empty array. Not sure if that will work for your situation.

@uwetews
Copy link
Contributor

uwetews commented Aug 12, 2018

count() has been changed with PHP 7.2. See http://php.net/manual/en/migration72.incompatible.php
It does only accept arrays or objects that implement Countable.
For that reason the |count modifier fails if the variable is unassigned or has a value of NULL.

The workaround is

{$c = $var|default:array()|count}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants