Warning: count(): Parameter must be an array or an object that implements Countable in _term_reference_tree_build_item() (Zeile 718 von /xxxxx/xxxx/sites/all/modules/term_reference_tree/term_reference_tree.widget.inc).

After updating on Drupal 7.61 und PHP 7.2 I receive this message, thanks for help.

The message appears when editing a node.

Jenna1

Comments

jenna1 created an issue. See original summary.

jenna1’s picture

Issue summary: View changes
hoporr’s picture

We saw this error as well when switching to 7.2.

There is a minor bug in the code @ line 202
(NOTE that the original report is for line 718, we had line 202; so there may be two related or different issues)

if (isset($tree['children']) && is_array($tree['children']) && count($tree['children'] > 0)) {

It has to be like this,

  if (isset($tree['children']) && is_array($tree['children']) && count($tree['children'])> 0) {

note in the original, that the closing parenthesis around 'count' is set wrong:
count($tree['children'] > 0)

In the original, the inner term in count resolves to a boolean test, instead of testing the array.
Apprently this was not caught in php < 5.x, and only with the 7.x being more strict does the bug show.

Sorry about not having this as a patch, but I had to do the fix directly on a system without diff/patch capabilities.

jenna1’s picture

I have now replaced line 202 with:
if (isset($tree['children']) && is_array($tree['children']) && count($tree['children'])> 0) {

I run cron and cache, but the message comes again for line 718:
Warning: count(): Parameter must be an array or an object that implements Countable in _term_reference_tree_build_item() (Zeile 718 von...

line 718
if (($depth + 1 <= $element['#max_depth'] || !$element['#max_depth']) && property_exists($term, 'children') && count($term->children) > 0) {

best regards, Jenna

fuerst’s picture

Status: Active » Needs review
StatusFileSize
new1.87 KB

Hi all, you got two errors covered here:

* Line 202: Missing parenthesis
* Lines 682/718: Accessing a non-Countable variable

The attached patch fixes both.

devenpro’s picture

Thanks, this patch works fine.

fuerst’s picture

Status: Needs review » Reviewed & tested by the community

  • alex_optim committed 2a75e05 on 7.x-1.x
    Issue #3016047 by fuerst, alex_optim: Parameter must be an array or an...
alex_optim’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
alex_optim’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

msnassar’s picture

Here is a patch for 7.x-1.11

joegl’s picture

We were getting this on 7.x-1.11 and the patch in #12 fixed it for us. It started showing up when we upgraded to 7.3. Should this be re-opened?