Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#3 | 2929115-fixing-operand-types-issue-form.patch | 740 bytes | danjuma9 |
Comments
Comment #2
techwolf12 CreditAttribution: techwolf12 at Unc Inc commentedComment #3
danjuma9 CreditAttribution: danjuma9 commentedI wrapped that line around an if statement, as the += array should only work if $element is an array. This seemed to fix my issue.
Comment #4
djdevinI 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
Comment #5
AporieGot 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:
Comment #6
vindesh CreditAttribution: vindesh as a volunteer and commentedIssue 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',
);
}