• When running PHP 7.4, I get the following warning on the logs:

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

    This is tied to line 302 of feedwordpress/syndicatedlink.class.php (at least on version 2017.1020.), which goes

    if (count($tombstones) > 0) :

    Now, when the variable $tombstones is, for example, a NULL, this will fail because NULL is neither an array nor an object. Earlier versions of PHP would equate any sort of error to the value zero (or FALSE), which meant you could be a little more careless about checks such as the above one. Contemporary versions of PHP are more demanding, even if they will often just throw a warning and not an error. In this case, a simple fix is to change line 302 to:

    if (is_countable($tombstones) && count($tombstones) > 0) :

    is_countable() has been introduced in PHP 7.3 exactly for this purpose.

    Possibly there are more instances like this in the rest of the code, but, for now, this easily fixes the warning (and makes it future-proof if the PHP developers decide to turn this particular warning into a fatal error, which they are prone to do over time…).

    FeedWordPress has few updates (it simply works…), but perhaps one of these days the developers of this fantastic plugin might make this small correction. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Note to self: just five days ago, a fix was pushed to the GitHub repository where FeedWordPress continues to be maintained which addresses this very same issue: https://github.com/radgeek/feedwordpress/pull/110

    The developer who made the change specifically addressed the case when $tombstones becomes NULL using code that is compatible with PHP versions earlier than 7.3 (other possible cases are not checked).

    We only need now to see the new version being released publicly 😀

    Plugin Author C. Johnson

    (@radgeek)

    Hey there, just wanted to let you know that I pushed all of the changes currently in github to the WordPress plugins repository. Let me know if this resolves the issue for you, if everything seems like it should, etc.! -C

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Awesome, thanks! I’ve forgotten to check this thread, but I believe you can safely mark it as closed/fixed/solved.

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    … whoops. Now PHP complains about line 708 in syndicatedpost.class.php. The culprit is in public function author (), and the relevant line is

    if (count($aa) > 0) :

    From PHP 7.3 onwards the solution is:

    if (is_countable($aa) && count($aa) > 0) :

    For earlier versions, there is a solution provided on the notes for is_countable().

    Plugin Author C. Johnson

    (@radgeek)

    Thanks for the catch on this. I will make a fix for this line. I’d be interested to know if you have the URL for a feed that gives you this warning? (If not, no worries — I realize it’s been a while. But if you do have the URL, then that would be useful because it gives me a test case for a condition that I’d like to remember to test for.)

    Thanks! I will reply again and close this thread out once the change is applied.

    WPTaTor

    (@wordpresstator)

    Hi!

    I have a similar Warning: count()* after the PHP upgrade to 7.4: https://frg-oy.com/

    Any help?
    Thanks in advance!

    *Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/29/d395190552/htdocs/clickandbuilds/FRGWorldwideOy/wp-includes/post-template.php on line 317

    Hello… Have you tried solution by @gwynethllewelyn ???

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘count(): Parameter must be an array or an object that implements Countable’ is closed to new replies.