[Defender Pro] PHP Warning from the Defender plugin

Hey guys,

I have marked this as a Defender issue but really I just want some enlightenment as to what the following error could be as it keeps on recurring;

PHP Warning: count(): Parameter must be an array or an object that implements Countable in /home/mysite/public_html/wp-content/plugins/wp-defender/app/module/ip-lockout/controller/main.php on line 643

Thanks

  • Adam Czajczyk
    • Support Gorilla

    Hi Baldafrican

    I hope you're well today and thank you for your question!

    This is a warning which means that's not really an "error" and in this particular case it shouldn't cause any issues with the site or how Defender works. Furthermore, it will not even be visible on every setup as whether it shows up in logs or not is mostly a matter of PHP error reporting settings.

    Basically, it's related to the changes in how "count()" function works in PHP since 7.2 version. Earlier it could be used to e.g. count the number of characters in strings and would cause issues if the value passed on to it would be e.g. "null". Since 7.2 it's been changed and in such cases it might throw such warning.

    The code where it's used is a bit specific due to the fact it must maintain backwards compatibility with earlier PHP versions. However, this particular warning should have been fixed with 2.1 release of Defender Pro as far as I'm aware.

    May I ask you if that's something older that you just found in logs or are you still getting it now? What's the exact PHP version that's powering your site?

    Best regards,
    Adam

    • Baldafrican
      • Made in Africa

      Hey Adam Czajczyk

      Thanks for the well wishes, I wish the same for you.

      May I ask you if that's something older that you just found in logs or are you still getting it now?

      It has been recurring for a while now as it keeps generating an entry in the error logs which defender picks up on. The last entries were yesterday.

      What's the exact PHP version that's powering your site?

      7.3.6

      Thanks for your help on this Adam Czajczyk it is, as usual, much appreciated!

      • Predrag Dubajic
        • Support

        Hi Mike,

        We were doing multiple tests with Defender developers but we're still unable to replicate this on any of the installations, could you perhaps provide us with FTP or cPanel access so we can have a closer look at your end?

        Note: Don't leave your login details in this ticket.
        Instead, you can send us your details using our contact form https://premium.wpmudev.org/contact/#i-have-a-different-question and the template below:
        NOTE: Don't change the selected topic in the dropdown, just leave it at "I have a different question".

        Subject: "Attn: Predrag Dubajic"
        - Site login URL
        - WordPress admin username
        - WordPress admin password
        - FTP credentials (host/username/password)
        - cPanel credentials (host/username/password)
        - Folder path to site in question
        - Link back to this thread for reference
        - Any other relevant urls/info

        Best regards,
        Predrag

  • David
    • New Recruit

    Predrag Dubajic We are seeing the same error:

    Warning: count(): Parameter must be an array or an object that implements Countable in /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-content/plugins/wp-defender/app/module/ip-lockout/controller/main.php on line 505

    Has a fix for this been released yet? We are aware this is only a notice but we have a practice of not knowingly deploying any PHP warnings or notices and this is holding up a large-scale upgrade to PHP 7.2.

  • David
    • New Recruit

    Also noting that trying to upgrade wpdefender-pro caused our entire site to break:

    Fatal error: Uncaught Error: Call to undefined method WPMUDEV_Dashboard_Site::get_wpmudev_branding() in /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-content/plugins/wp-defender/main-activator.php:48
    Stack trace:
    #0 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-includes/class-wp-hook.php(286): WD_Main_Activator->prepareBrandingInfo('')
    #1 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
    #2 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
    #3 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-settings.php(394): do_action('plugins_loaded')
    #4 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-config.php(175): require_once('/srv/bindings/5...')
    #5 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-load.php(37): require_once('/srv/bindings/5...')
    #6 /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-blog-header.php(13): require_once('/srv/bindings/5...')
    #7 /srv/ in /srv/bindings/5e27bac3aeaf451084ebf8e3edb6fac1/code/wp-content/plugins/wp-defender/main-activator.php on line 48

  • Predrag Dubajic
    • Support

    Hi David,

    Our developers are still looking into the warning, I don't have any ETA at the moment I'm afraid.

    Also noting that trying to upgrade wpdefender-pro caused our entire site to break:

    It looks like some of the files didn't get transferred properly so the plugin is missing some functionality which causes fatal error.
    Could you please go to Defender page here https://premium.wpmudev.org/project/wp-defender/ and download the plugin manually.
    After that access your files via FTP or cPanel and replace the current Defender version with the one you downloaded manually.
    That should ensure that the plugin files are all there and should solve the issue.

    If you are still having problems after that please start a new ticket or chat so we can investigate this further.

    Best regards,
    Predrag

  • David
    • New Recruit

    Hi Predrag Dubajic thanks for the quick response. The issue was actually that we updated wp-defender but also needed to update the wpmudev-updates plugin as well as the wp-defender calls new methods in the other plugin.

    Upgrading both of these did not resolve the count() PHP error. Please continue to push for an update to make this plugin PHP 7.2 compatible.

    Thanks!

  • Adam Czajczyk
    • Support Gorilla

    Hello Baldafrican David

    As for the "count()" error, I've attached to zip files called "patch1.zip" and "patch2.zip" to this post. They contain alternative possible patches for the issue so could I ask you for a little help?

    Since I'm not able to trigger that error in any way on my setups, I could use a hand. Could you please try them both - not at once, of course, just test one and the other one after that and let me know if they both or one of them fixes the issue for you and if so, if the plugin seems to be working fine.

    To apply any of these patches, simply download the zip file and extract it to your local drive first. Each file contains the same "main.php" file (just with different changes) so the file should be uploaded to the site to the

    /wp-content/plugins/wp-defender/app/module/ip-lockout/controller/

    folder, overwriting existing main.php file there. Just please make sure to make a copy of the original file to be able to restore it in case anything went wrong (in such case restoring original file will immediately reverse any changes).

    I'd appreciate your help on this. Let me know about results please.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.