skip to Main Content

I’m getting this error in WordPress and I don’t know what it’s asking. Here is the code starting on line 436.

if (count($this->keys) && $this->action == 'add') {
                
                // Extract the last key
                $last = $this->keys[count($this->keys) - 1];

                // Are we trying to add stuff?
                if ($last == $this->add_key) {
                    $this->data = $this->set_data($this->default, $this->keys);             
                }

            }

Its in a plug in called ‘more fields. Its updated.
I don’t know what to try. PHP isn’t my forte.

2

Answers


  1. Chosen as BEST ANSWER

    Well, ChatGPT pointed out that

    $this->keys
    

    Might not be an array in some contexts. I would have never guessed that, but PHP isn't my forte. ChatGPT suggested checking to see if it was an array before implementing.

    The fix:

    if (is_array($this->keys) && count($this->keys) && $this->action == 'add') {
    // Extract the last key
    $last = $this->keys[count($this->keys) - 1];
    
    // Are we trying to add stuff?
    if ($last == $this->add_key) {
        $this->data = $this->set_data($this->default, $this->keys);             
    }
    

    }

    Looks to be working and implemented well with the old plug in. If there is anything anyone else would like to point out, I'm all ears and willing to learn. Thank you.


  2. Arrays, Generators, Objects (with public properties) and Iterators are implementing the Countable Interface.

    If it is not one of those types you will get this error.

    To fix this error you can check if it is countable.

    if (is_countable($this->keys) && count($this->keys) && $this->action == 'add')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search