Hi!

Problem/Motivation

On Drupal 7.x, running on a FreeBSD (11.1-RELEASE-p1) server with PHP 7.1.12, I get the following message opening a page with forms:
Error: Unsupported operand types in form_builder() (line 1812 of (path to htdocs)/includes/form.inc).

It seems this code is causing the error:

$element += array(
    '#required' => FALSE,
    '#attributes' => array(),
    '#title_display' => 'before',
   );

Proposed resolution

Rewriting it as such seems to fix my issue:

$element = array_merge($element, array(
    '#required' => FALSE,
    '#attributes' => array(),
    '#title_display' => 'before',
   ));

I'm not sure if this is the correct way, I will discuss it later with some other developers and update with a patch accordingly.

Kind regards,

Christiaan

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

techwolf12 created an issue. See original summary.

techwolf12’s picture

Issue summary: View changes
danjuma9’s picture

I wrapped that line around an if statement, as the += array should only work if $element is an array. This seemed to fix my issue.

djdevin’s picture

Status: Active » Closed (cannot reproduce)

I came across this too but it's not reproducible in core. Seems like modules that alter the book forms are to blame:

#2930286: _outline_designer_book_admin_form_alter incompatible with PHP 7.1+
#2871962: PHP7 support

Aporie’s picture

Got the same issue here. It's probably due to another module as djdevin said though to hotfix it, you can apply this solution (which is probably not the proper one).

The solution described in the ticket details was braking views for me, so I would rather go for:

  $element['#required'] = isset($element['#required']) ? $element['#required'] : FALSE;
  $element['#attributes'] = isset($element['#attributes']) ? $element['#attributes'] : array();
  $element['#title_display'] = isset($element['#title_display']) ? $element['#title_display'] : 'before';
vindesh’s picture

Issue resolved, i applied below code -

includes/FORM.inc
Line number: 1816
// Assign basic defaults common for all form elements.
if (is_array($element)) {
$element += array(
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'#attributes' => isset($element['#attributes']) ? $element['#attributes'] : array(),
'#title_display' => isset($element['#title_display']) ? $element['#title_display'] : 'before',
);
}