• Hi,

    still finding some little flaws. Plugin works good so far, but I get my error log filled with this warning:

    PHP Warning: count(): Parameter must be an array or an object that implements Countable in … plugins/speakout/includes/class.petition.php on line 321

    While you are looking after the UTF8 problem, could you look after this warning as well? Thanks in advance and greetings from Germany!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sixtyseven

    (@sixtyseven)

    Came up with a litte solution for that: Seems that the warning was added in PHP 7.2. From PHP 7.3 there will be a native function called is_countable(). To be compatible with lower PHP versions as well, you could add a little polyfill like function to your plugin, like so:

    if (!function_exists('is_countable')) {
    
        function is_countable($c) {
            return is_array($c) || $c instanceof Countable;
        }
    
    }

    With that implemented, you could change the lines in class.petition like so:

    if(is_countable($petition)){
    if ( count( $petition ) > 0 ) {
    $this->_populate_from_query( $petition );
    return true;
    } else {
    return false;
    } else {
    return false;
    }

    or something more clever of course 😉 Can’t wait to get my hands on the next update, thanks again for your nice plugin.

    Plugin Author SpeakOut! Steve

    (@123host)

    Thanks for your contribution.

    I have done some research on this and I think that a less complex way to do this is instead of if ( count( $petition ) > 0 ) to use if ( $petition && $petition > 0 )

    I have run some tests and it seems to be OK. Can you test it too?

    Thread Starter sixtyseven

    (@sixtyseven)

    Thanks, will do after my return from Tunisia on Juli 24th.

    Plugin Author SpeakOut! Steve

    (@123host)

    As far as I can tell this is fixed now. Would appreciate if you can confirm that. I am about to push version 1.13.0

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PHP warning’ is closed to new replies.