1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

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

Discussion in 'Development' started by Kabluinc, Sep 24, 2017.

  1. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    I'm getting this error since the PHP 7.2 update:

    Code:
    [16:26:31] [Server thread/CRITICAL]: Unhandled exception executing command 'f create test' in f: count(): Parameter must be an array or an object that implements Countable
    [16:26:31] [Server thread/CRITICAL]: ErrorException: "count(): Parameter must be an array or an object that implements Countable" (EXCEPTION) in "plugins/GuildsRPG-master/src/FactionsPro/FactionCommands" at line 46
    Code relevant to that line:

    PHP:
    if (count($args == 2)) {
    Please help
     
  2. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Any idea how to fix this?
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    :facepalm: :facepalm: :facepalm:
    Read error "Parameter must be an array or an object that implements Countable"
    It means "== 2" don't have to be inside count() BECAUSE it don't implements Countable :D
     
    Last edited: Sep 24, 2017
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    PHP:
    if (count($args) === 2) {
     
    Levi, jasonwynn10 and Kabluinc like this.
  5. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    What happened is you put the == inside the count() function. Here's what's happening:
    PHP:
    $foo $args == 2
    var_dump
    ($foo// (bool) false
    // $args is not equal to 2, therefore $args == 2 evaluated to false
    So since
    PHP:
    $args == 2
    returns false, you're pretty much saying
    PHP:
    count(false)
    . The count() function accepts an array as a parameter, and you're giving it a boolean. Just put the == outside of the count() function.
    (I know all this explanation was probably very unnecessary, I just wanted to explain to the OP exactly what was happening)
     
  6. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    TYSM everyone
     
  7. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Try the latest builds of FactionsPro in the CI section of Poggit. These bugs, and more have now been fixed.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.