• Running PHP 7.2, I am seeing sporadic entries to my error log:

    PHP Warning: count(): Parameter must be an array or an object that implements Countable in ________ wp-includes/post-template.php on line 284

    I have determined that this error warnings are triggered by some multi-term searches on our site — and I can replicate the error by entering the same search terms in the search field on any page of the site. However, other searches do not trigger the error.

    For example, if I found the error triggered by a search for big+black+dogs — I could enter the words: big black dogs – in the search box and the warning will be generated. But if I make a different search — for example, big brown dogs — then I don’t see the error. So I assume that it must be a particular set of search terms that in turn produces results that trigger the PHP 7.2 warning.

    I don’t consider this to be a major problem — just a quirk of PHP 7.2 — but it is enough of an annoyance to me that I plan to revert back to PHP 7.1 I’m reporting this simply because it does seem to be a Relevanssi use issue, perhaps only in an edge case scenario.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Couple of guesses: you’re using the_content() on your search results template and the problem search results somehow involve multi-page posts?

    What that count() is trying to count is the global $pages variable, which has the content of the post, split into individual pages. That should be a basic PHP array and thus implement Countable.

    Using the_excerpt() with Relevanssi-generated excerpts should not cause this problem, as that does not trigger the get_the_content() function.

    I’m not sure what this has to do with Relevanssi. PHP is complaining about the $pages array not being Countable, but Relevanssi never touches that array. I wasn’t able to reproduce the issue, so I don’t know what’s up with it.

    Thread Starter Abigailm

    (@abigailm)

    Thanks for the feedback — I didn’t know if this was tied to Relevanssi, the theme, or core wordpress function. I just reported it here because it was tied to search function. My theme template does not seem to use the_content() in search results — but that is helpful information to narrow down the source of the issue.

    Thread Starter Abigailm

    (@abigailm)

    @msaari — I tested by using a search that caused the error and doing the same search with Relevanssi de-activated as well as activated. If the plugin is de-activated.. then no error.

    So I am back to thinking that there is something that is happening with Relevanssi on some, but not all, searches that is causing the error. My system does have a large array of custom post types being indexed — so it is not simply posts & pages.

    Other users reporting this PHP 7.2 warning in other context have said that it occurs if they use get_the_excerpt () and the page has no excerpt.

    This is at https://core.trac.wordpress.org/ticket/42814

    On my site, some pages/posts have excerpts and some don’t. I currently have Relevanssi options set to create custom excerpts — so I see the custom excerpt displayed on the results page — but I am wondering if there is still something in the Relevanssi code that might be triggering the error.

    It’s not a huge problem and I can always revert to PHP 7.1… but Relevanssi is such an amazing plugin that I’d also like to see this nailed down for the future.

    Plugin Author Mikko Saari

    (@msaari)

    I don’t think Relevanssi is doing anything in particular to cause this issue. It seems to me the problem is caused by those global arrays being null in some cases when they shouldn’t, and Relevanssi is simply not touching those arrays.

    So while Relevanssi does trigger the error in some circumstances, the root cause for the error is somewhere else and there’s as far as I can tell nothing to change in Relevanssi to avoid the error. One explanation might be that Relevanssi includes a post in the search results that triggers the error, and the default WP search does not find that post with the same search, thus avoiding the error.

    Relevanssi, for example, doesn’t call get_the_excerpt() or get_the_content() at all. Relevanssi gets the post content directly from the $post object, so I’m not sure how get_the_content() is being called in the first place (as it has to be, since that’s the function that triggers the error).

    If you disable Relevanssi excerpts, do you still get the error?

    Thread Starter Abigailm

    (@abigailm)

    If I disable the Relevanssi “Custom search result snippets” options and run the same search, there is no error message.

    So it does seem to be tied to the Relevanssi custom excerpts option, rather than the specific search results.

    Plugin Author Mikko Saari

    (@msaari)

    There’s this line in Relevanssi’s lib/excerpts-highlights.php file:

    $content = apply_filters( 'the_content', $content );

    If you comment it out (add a // in front of it) and enable Relevanssi excerpts, do you still get the error?

    Can’t really think of any other place in Relevanssi that could trigger something like this.

    Thread Starter Abigailm

    (@abigailm)

    Thanks — I found that @ line 51 in the file — and commenting it out does seem to have eliminated the error.

    Would that impact function of the plugin in any other way that I should be aware of?

    • This reply was modified 5 years, 11 months ago by Abigailm.
    Plugin Author Mikko Saari

    (@msaari)

    Yeah, it can have surprising results. My main point here is that this is indeed not a Relevanssi issue. Your site has some function on the the_content filter hook, and that’s causing the problem.

    So, instead of disabling the_content filter completely, it’d be better to see what’s added to the hook and see which filter function is causing this problem.

    Thread Starter Abigailm

    (@abigailm)

    Thank you. As noted, my site has a number of different custom post types, created with the Pods plugin. Relevanssi is wonderful because of the way it allows me to fine-tune how the search facility works with various different types of posts & categories — and I am guessing that the PHP error is triggered only when the search leads to specific custom post types.

    To help me better understand the problem, can you clarify whether the_content filter in the /lib/excerpts-highlights file has any function other than managing the highlighting feature for the search results? I am seeing highlighting working without any apparent problem even with that filter disabled … but I agree that it is best long-term for me to find a better solution.

    Plugin Author Mikko Saari

    (@msaari)

    It applies the_content filters to the post content, allowing your other plugins to do their work. For example, it expands all the shortcodes. Relevanssi in itself does nothing there, Relevanssi functionality will not suffer if you disable that filter hook.

    But I’d look at what filter functions you have on that hook, one of those is the reason behind these errors.

    If you want a list of filters on the_content, you can do this:

    global $wp_filter;
    var_dump($wp_filter['the_content']);
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘PHP 7.2 Warning on some searches’ is closed to new replies.