#49895 closed defect (bug) (duplicate)
PHP Warning: count(): Parameter must be an array or an object that implements Countable
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 5.4 |
Component: | Posts, Post Types | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
This is a follow-up to #42814.
After upgrading from PHP 5.3 to PHP 7.4.4, on the latest wordpress 5.4 I am getting this warning often.
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/html/wp-includes/post-template.php on line 317
Change History (6)
#3
@
5 years ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Hi there, welcome to WordPress Trac!
Thanks for the report, we're already tracking this issue in #47824.
#4
in reply to:
↑ 1
;
follow-up:
↓ 6
@
5 years ago
- Resolution duplicate deleted
- Status changed from closed to reopened
Replying to afragen:
It seems that, in this case, in the function
get_the_contents()
theglobal $pages
, which is defined as an array, is not returning an array into the function.
The cause of this needs to be investigated. Is this reproducible on other sites for you running PHP 7.4.x? Personally, I'm not seeing this error.
I don't know if it is reproducable yet. What I have noticed is that it might be related to the Events Manager plugin, because it seems to be occurring on events pages. But I checked their template php file, and they have the have_posts()
check, so I can't figure what could be the issue.
<?php <?php if ( have_posts() ) : ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php $post = get_post(); $EM_Event = em_get_event($post->ID, 'post_id'); ?> <?php the_content(); ?>
Inside the event manager template itself then there is a global $EM_Event;
Still not sure why this would propagate inside the code of WordPress, it should be sufficiently self contained.
#5
@
5 years ago
- Resolution set to duplicate
- Status changed from reopened to closed
Duplicate of #47824.
#6
in reply to:
↑ 4
@
5 years ago
Replying to jbx:
But I checked their template php file, and they have the
have_posts()
check, so I can't figure what could be the issue.
This is still a duplicate of the other ticket. The existence of a have_posts()
check does not a proper Loop make.
"The Loop" specifically exists when the_post()
is called. This sets up the various globals. Without such a call, then the globals aren't set, and so you are calling the_content()
outside of a proper Loop.
Putting the results of get_post()
into a global $post
isn't good enough to make a Loop.
In any case, being tracked in the other ticket.
It seems that, in this case, in the function
get_the_contents()
theglobal $pages
, which is defined as an array, is not returning an array into the function.The cause of this needs to be investigated. Is this reproducible on other sites for you running PHP 7.4.x? Personally, I'm not seeing this error.