views_many_to_one_helper::add_filter() performs count() on a variable that may not be an array. In PHP 7.2 this generates a warning with the following text:

Warning: count(): Parameter must be an array or an object that implements Countable in views_many_to_one_helper->add_filter() (Line 1090 in views/includes/handlers.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jorrit created an issue. See original summary.

Jorrit’s picture

Status: Active » Needs review
FileSize
448 bytes

Please see the attached patch.

DamienMcKenna’s picture

Status: Needs review » Reviewed & tested by the community
Parent issue: » #2960871: Plan for Views 7.x-3.23 release

Thanks!

dsnopek’s picture

Issue tags: +panopoly

RTBC+1! Used in Panopoly

  • DamienMcKenna committed af9e128 on 7.x-3.x authored by Jorrit
    Issue #2977851 by Jorrit, dsnopek: PHP 7.2: count() on non-Countable in...
DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +PHP 7.2

Committed. Thanks!

Status: Fixed » Closed (fixed)

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

cboyden’s picture

The patch in #2 does not apply to Views 7.x-3.21, here's a re-roll.

darrell_ulm’s picture

The patch in #2 does not apply to Views 7.x-3.23, here's an additional re-roll.

darrell_ulm’s picture

And here is the file mentioned in #9

xlin’s picture

Alina Basarabeanu’s picture

This issue was fixed previously with the patch from #2 but we lost it with this commit https://git.drupalcode.org/project/views/commit/fbafd79a763f19d8c06039f3...

@DamienMcKenna please change this ticket back to needs review

demonde’s picture

I have a similar issue

Error message
Warning: count(): Parameter must be an array or an object that implements Countable in views_handler_argument_term_node_tid_depth->query() (line 110 of drupal7/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc).

The code in views_handler_argument_term_node_tid_depth.inc should be probably changed in a similar way from

if (count($tids->value) > 1) {

to

if (is_array($tids->value) && count($tids->value) > 1) {

michfuer’s picture

Agreed with #11 and #12, the patch in #2 appears to have been unintentionally reverted when the 7.x-3.21 security updates were merged into the 7.x-3.x branch.

A maintainer should re-open and probably set to 'Needs review' for the patch in #14.

DamienMcKenna’s picture

Status: Closed (fixed) » Needs review

Whoops.

PSA: this is why we need moar test coverage (-:

rclemings’s picture

End of security support for PHP 7.1 is about five weeks ago. Any way this patch could be in a release before then?

VladimirAus’s picture

Updating patch with a bit of optimisation.

Status: Needs review » Needs work

The last submitted patch, 18: 2977851-views-php72-count-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

This line doesn't need the extra brackets around the is_array() statement:

if ((is_array($value)) && (count($value) > 1)) {
VladimirAus’s picture

Status: Needs work » Needs review
FileSize
1.96 KB

Cheers @DamienMcKenna.
Updated patch.

Status: Needs review » Needs work

The last submitted patch, 21: views-php72_count-2977851-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

DamienMcKenna’s picture

Rerolled.

Let's fix this for the next release.

DamienMcKenna’s picture

DamienMcKenna’s picture

Issue tags: +Regression

Status: Needs review » Needs work

The last submitted patch, 24: views-n2977851-23.patch, failed testing. View results

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
4.16 KB

How about this? I'm reverting part of the change in the hopes of limiting what causes problems, we can deal with other count() problems in another issue.

DamienMcKenna’s picture

Status: Needs review » Fixed

Ok, this more limited change passes for both 7.4 and 8.0, so that's sufficient for now.

  • DamienMcKenna committed a15f92b on 7.x-3.x
    Issue #2977851 by DamienMcKenna, VladimirAus, Jorrit, darrell_ulm,...
brandonpost’s picture

Status: Fixed » Needs review
FileSize
1.35 KB

Hi Damien, the patch for this issue released in 7.x-3.26 appears to be causing some problems (please see Views 7.x-3.26 breaks glossary view of taxonomy terms causing "SQLSTATE[42000]: Syntax error or access violation: 1064).

I see how patch #27 attempts to simplify the logic, but it doesn't take into account the case if $value is a nested array. The original logic did that, but the problem with the original logic is that it didn't test is_array($value) before calling count($value).

Here is a patch that reverts back to the original logic, but adds is_array($value), which solves the original issue of 'count() on non-Countable'. The patch also implements demonde's suggestion in #13 to make the same correction in views_handler_argument_term_node_tid_depth.inc.

brandonpost’s picture

Just saw another potential issue with the original logic. Here's an updated patch.

brandonpost’s picture

One more patch also incorporating a correction to views_handler_argument_term_node_tid_depth_join.inc that VladimirAus had made in #21.

ethomas08’s picture

Patch #32 does not work for me for the 7.x-3.26 release for the glossary bug my team is experiencing (more info in duplicate issue: https://www.drupal.org/project/views/issues/3305385)

Uploading a patch that fixes this error, from one of Damien's commits.

Status: Needs review » Needs work

The last submitted patch, 33: views-php72-count-2977851-33.patch, failed testing. View results

DamienMcKenna’s picture

@ethomas08: Please clarify what happens when you tried #32, in what way did it not work?

DamienMcKenna’s picture

Status: Needs work » Fixed

Committed. Again. Thank you.

  • DamienMcKenna committed 8ad624e on 7.x-3.x
    Issue #2977851 by brandonpost, DamienMcKenna, ethomas08: Follow up: PHP...

Status: Fixed » Closed (fixed)

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