Warning: count(): Parameter must be an array or an object that implements Countable in (\:directory) on line 436 [duplicate]
Warning: count(): Parameter must be an array or an object that implements Countable in (\:directory) on line 436 [duplicate]
This question already has answers here:
Reference - What does this error mean in PHP? (38 answers)
phpmyadmin - count(): Parameter must be an array or an object that implements Countable (40 answers)
Closed 11 days ago.
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.
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')
December 30, 2023
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.
December 30, 2023
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand
December 30, 2023
December 30, 2023