Automatic conversion of false to array is deprecated in ctools_context_create_user_edit_form()

Created on 13 October 2022, over 1 year ago
Updated 30 June 2023, about 1 year ago

Problem/Motivation

The module causes this error.

Deprecated function: Automatic conversion of false to array is deprecated in ctools_context_create_user_edit_form() (line 35 of / ... /ctools/plugins/contexts/user_edit_form.inc).

That error is caused by the fact that the default value for $conf is FALSE, not an empty array. When ctools_context_create_user_edit_form() is called as ctools_context_create_user_edit_form($empty, $user), $conf is set to FALSE and $category = !empty($conf['category']) ? $conf['category'] : FALSE; tries to access a Boolean value as an array, which is not anymore allowed with PHP 8.

Proposed resolution

I propose the following code change.

From

function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALSE) {
  // Determine the user category.
  $category = !empty($conf['category']) ? $conf['category'] : FALSE;
  unset($conf['category']);

  // If no category was specified, use the default 'account'.
  if (!$category) {
    $category = 'account';
  }

To

function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALSE) {
  // Determine the user category.
  $category = !empty($conf['category']) ? $conf['category'] : 'account';

  if (isset($conf['category'])) {
      unset($conf['category']);
  }
🐛 Bug report
Status

Needs review

Component

Code

Created by

🇬🇧United Kingdom jonnyToomey

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024