PHP 8: Argument #1 ($array) must be of type array, null given in array_intersect_key()

Created on 14 June 2023, over 1 year ago
Updated 24 October 2023, about 1 year ago

Problem/Motivation

In some circumstances, legal_user_is_exempt() may be called when the user object has no roles attached. In this case, it should simply return FALSE, instead of causing error.

Steps to reproduce

Not entirely sure.

Proposed resolution

Test for presence of roles and return false if none.

Remaining tasks

Patch to follow

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States gbirch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gbirch
  • Open in Jenkins → Open on Drupal.org →
    Core: 7.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    20 pass
  • 🇮🇳India abhishek_virasat

    @gbirch, can you please share step to reproduce. that I verify your patch , its working or not.

  • 🇺🇸United States gbirch

    As noted in the issue description, I was unclear at the time of the report about the circumstances in which the passed user might be anonymous - I had the error, but not a lot of detail about the circumstances in which it was triggered. So I simply wrote a patch that tested for the existence of an array before calling a function that requires an array - pure defensive programming. But I now know that it can happen when using the Masquerade module and a user who has masqueraded now de-masquerades. Why this should be true I have not chased down, but honestly, this patch simply makes the code work when an anonymous user object is passed, which seems like good coding practice to me.

Production build 0.71.5 2024