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

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

Open
Redolance opened this issue Oct 28, 2019 · 1 comment

Comments

@Redolance
Copy link

This error appears when no repeatable filed are created.
Warning: count(): Parameter must be an array or an object that implements Countable in :
admin-page-class\admin-page-class.php on line 1398
You can fix this just by change the order of checking if on line 1398 from :
if (count($meta) > 0 && is_array($meta) ){
to
if ( is_array($meta) && count($meta) > 0 ){
so If $meta is empty it will stop cheking for count.
Hope this will help someone.

@StonehengeCreations
Copy link

StonehengeCreations commented Oct 28, 2019

This is not an error, but a warning. There is a big difference - a warning will not stop the script from being executed, an error will.

This notice was introduced in PHP 7.2, so anything lower will not show this warning. Also, your solution is incorrect. Your coding will stop reading further is $meta is not an array, but the count() warning will still show.

count() can still count arrays and objects, it just needs to be told what it it:
if( count( (array) $meta ) > 0 && is_array( $meta ) )

Also, this code was last committed in 2014, long before PHP 7.2 was released. With PHP 7.4 to be released in November, you can probably expect more warnings for deprecated functions.

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

2 participants