Hello, i have recently updated my php to 8.0 and realized a exposed filter changed how it works.

I'm using better exposed filters over the views, but i traced the issue to the views module.

When i have a boolean operator filter, and better exposed filter module assigns a default value of 0 (false), the "acceptExposedInput" method in Drupal\views\Plugin\views\filter\FilterPluginBase behaves differently.
At line 1507 of FilterPluginBase.php there is this condition, which evaluates to true (0=='string') in php7.4 and to false in php 8.0.

          if ($value == 'All' || $value === []) {
            return FALSE;
          }

Also lines 111, 112 and 113 at Drupal\views\Plugin\views\filter\BooleanOperator look redundant to me.

Kind regards and many thanks for your awesome work.

Comments

Pandepoulus created an issue. See original summary.

pandepoulus’s picture

Issue summary: View changes
pandepoulus’s picture

Issue summary: View changes
cilefen’s picture

What should be done here? Should you pick another default value?

pandepoulus’s picture

Well, booleanOperator filters with a default value of false are not filtering in php 7.4, which i think is an error, but are working properly with php 8.0.

probably just changing the condition to strcmp($value,'All') == 0 whould lead to same results regarding the php version.
Not sure something has to be done as i think is working fine in php 8.0
.

cilefen’s picture

Yes, this is an interesting one.

cilefen’s picture

Title: module works different in php 7.4 than in php 8.0 » Exposed filter equality check works differently in PHP 8.0
nagy.balint’s picture

We see the same problem on PHP8.

Its indeed related to https://www.php.net/manual/en/migration80.incompatible.php

strcmp likely wont work, as the value can be array as well, and strcmp needs a string.

mr.york’s picture

StatusFileSize
new636 bytes

I created hotfix.

lendude’s picture

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jaims-dev’s picture

Priority: Normal » Major
Status: Active » Reviewed & tested by the community
Issue tags: +PHP 8.1

I can confirm that this is still an issue, and I can also confirm that the patch solved it.

It believe it should be reprioritazed as 'major' because for one particular site, views went from working to not working well (i.e. omitting rows that should be displayed) when updating the site from php7.4 to php8.1 (Drupal version is 9.4.8). As many sites will be updated to php8+ in the next months, this can really be considered an important issue.

Also, tagging this as RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

I can confirm the issue and that the fix looks okay... see https://3v4l.org/1t3f1

Ideally we'd have automated test coverage that would have caught this issue. But obviously we don't as this would have been fixed when we started testing on PHP 8. I think we should take this opportunity to add the missing coverage.

lendude’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.03 KB
new2.65 KB

Here is a test for this, doing this in a functional test is very involved, so simple unit test

Lets see if this give the expected pass/fail. The test only patch is the interdiff

lendude’s picture

StatusFileSize
new2.02 KB
new2.64 KB

And lets try that again....

The last submitted patch, 15: 3259090-15-TEST_ONLY.patch, failed testing. View results

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

lendude’s picture

Also ran the 'test only' on PHP7.4 and as expected it goes green there, so this seem to catch the bug as expected.

alexpott’s picture

Version: 9.4.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Nice test.

Committed and pushed 812ec978db to 10.1.x and e11c30b58a to 10.0.x and ee3fedcd24 to 9.5.x. Thanks!

I think 9.4.x has had it's last bugfix release so this goes in 9.5.x

  • alexpott committed 812ec97 on 10.1.x
    Issue #3259090 by Lendude, mr.york, Pandepoulus: Exposed filter equality...

  • alexpott committed e11c30b on 10.0.x
    Issue #3259090 by Lendude, mr.york, Pandepoulus: Exposed filter equality...

  • alexpott committed ee3fedc on 9.5.x
    Issue #3259090 by Lendude, mr.york, Pandepoulus: Exposed filter equality...

Status: Fixed » Closed (fixed)

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