Php 7

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

Bạn đang xem: Php 7

I"m getting the above sầu error on the following line.

if (0 >= count($this->xprop))Can someone help me understvà this? I"m fairly new lớn PHP. The issue is obviously with $this->xprop not being an array. It wasn"t an issue before I upgraded khổng lồ PHP 7.2. How can I get around this? Are code with warnings still being executed or is this going lớn cause execution khổng lồ fail?

I"ve sầu tried to follow the second answer on here with no luông xã. The accepted answer is not acceptable to lớn me as it is more of a haông xã.

php wordpress
asked Aug 21 "18 at 23:22

48755 silver badges1515 bronze badges
| Show 13 more comments

4 Answers 4

Active sầu Oldest Votes
PHPhường 7.2 throws an error when trying to count, or get the form size of, a variable that isn"t phối. In previous versions, authors would shortcut checking lớn see if the variable was phối by just counting (or sizeof"ing) it, và getting "0" on an unphối variable.

The solution is to kiểm tra khổng lồ see if it"s phối before counting it:

if (isset($this->xprop) &và count($this->xprop) == 0)Your example above sầu is actually negative xúc tích, and is a pretty strange way of stating "if the form size of this array is zero, or less than zero" (which is impossible). So, following your example above, the PHPhường. 7.2 compliant version would be khổng lồ use empty:

if (empty($this->xprop))... because a variable can be phối ($xprop = array()) but still be empty.

Xem thêm: phần mềm xuân phi

Sorry if this is a bit unclear; it"s late here!


edited Aug 22 "18 at 17:07
answered Aug 22 "18 at 2:31

61855 silver badges99 bronze badges
Add a phản hồi |
the problem is caused because of the PHPhường version.

In PHPhường 7.2 , the count() method does not tư vấn null as argument .

Example :

in PHP. 5.6.x :

emang lại count(null); // this show 0 in PHPhường 7.2.x :

emang lại count(null); // count(): Parameter must be an array or an object that implements Countable So you should verify if the variable is not null

answered Aquảng cáo 16 "19 at 16:16

Mohammed Yassine CHABLIMohammed Yassine CHABLI
2,69222 gold badges1313 silver badges3636 bronze badges
Add a comment |
if you are using php7.3 or above you can use is_countable before the count


answered Aug 16 "19 at 8:13

Gehad MohamedGehad Mohamed
11111 silver badge55 bronze badges
Add a comment |
There are some ways, but I lượt thích the new ??-operator, because it is short:

$null = null;emang lại count($null); // Warning: count(): Parameter must be an array or an object that implements Countableemang lại is_countable($null) ? count($null) : 0; // => 0emang đến count((array)$null); // => 0emang đến count($null ?? <>); // => 0
answered Feb 24 "trăng tròn at 11:30


37622 silver badges55 bronze badges
Add a phản hồi |

Your Answer

Thanks for contributing an answer lớn Stachồng Overflow!

Please be sure lớn answer the question. Provide details và giới thiệu your research!

But avoid

Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; bachồng them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Thư điện tử & Password

Post as a guest

Email Required, but never shown

Post as a guest


Required, but never shown

Post Your Answer Disthẻ

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy & cookie policy

Not the answer you're looking for? Browse other questions tagged php wordpress or ask your own question.

The Overflow Blog
Featured on Meta
PHPhường. 7.2 count() function is not working
Coverage phpunit on Laravel 5.2
How can I prsự kiện SQL injection in PHP?
Deleting an element from an array in PHP
startsWith() và endsWith() functions in PHP
How vì you parse và process HTML/XML in PHP?
Reference — What does this symbol mean in PHP?
How does PHP 'foreach' actually work?
Reference - What does this error mean in PHP?
Why shouldn't I use mysql_* functions in PHP?
Hot Network Questions more hot questions

Question feed
Subscribe lớn RSS
Question feed To subscribe to this RSS feed, copy & paste this URL into lớn your RSS reader.

Staông xã Overflow
Staông chồng Exchange Network
site design / biệu tượng công ty © 2021 Staông chồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.6.25.39582

Stack Overflow works best with JavaScript enabled

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and discchiến bại information in accordance with our Cookie Policy.