Problem with element_children method when weight is not scalar

Created on 3 August 2021, over 3 years ago
Updated 3 March 2023, almost 2 years ago

Problem/Motivation

In the common.inc a recent change made in https://www.drupal.org/node/2756297 β†’ causes errors.
There used to be a scalar check but now the value of weight could be anything.
This was no problem until the calculation was added.

Steps to reproduce

Set the weight too for example an array [0, 0] and notice that we get an error.

Error: Unsupported operand types in element_children()

Proposed resolution

Add the scalar check to the weight value.
Patch is added.

We accidentally came across the issue when updating to the latest security update 7.82.

πŸ› Bug report
Status

Needs work

Version

7.0 ⚰️

Component
BaseΒ  β†’

Last updated 37 minutes ago

Created by

πŸ‡³πŸ‡±Netherlands thomasdik

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡¦πŸ‡ΊAustralia CBEEM

    This is an issue for me on a production site, Drupal on cPanel on a remote Internet host so I do not have much access to settings etc.

    Drupal 9.3, 9.4 or 9.5 all produce the error when trying to add a new user:
    Error: Unsupported operand types in Drupal\Core\Render\Element::children() (line 93 of core\lib\Drupal\Core\Render\Element.php)

    On PHP 7.4 everything is fine, but any flavour of PHP 8 produces the error.

    On my local setup (Drupal 9.3 - 9.5) (PHP 8.0 - 8.1.16) everything works fine.

    Also I do not have the issue on Drupal 9.5 on other remote hosts (also PHP 8.1.16).

    For the affected site there are some customisations on my login form, but this does not produce any issues on my local copy with PHP 8.1.13 or 8.1.16. The customisations use a Profile form from the Profile module, I only have one profile set up which provides a few items to agree to before clicking a checkbox to proceed. This is set to display on the registration form. This has worked just fine for years in every update of Drupal and works on my local setup.

    Might there be some issue in the Profile module? Or something to do with core?

    Any insight would be appreciated, I am unable to update the Drupal site without PHP 8.

    Thanks :)

  • πŸ‡¦πŸ‡ΊAustralia CBEEM

    Got this working. I have no idea why it is only this host that is affected, but for this particular host an edit to core fixed the issue:

    Drupal 9.5.4

    /web/core/lib/Drupal/Core/Render/element.php

    Line 93:
    Change: "$child_weights[$key] = floor($weight * 1000) + $i / $count;"
    to: $child_weights[$key] = floor((int)$weight * 1000) + $i / $count;

    The user registration form is now functioning again and errors are no longer appearing in the logs.

    The Drupal database is updating OK and all looks good.

    I do not particularly want to be editing core every time I update this sight. I wonder if anyone has some insight into why this might be happening just for this host? Maybe something not installed in PHP on the server?

    Cheers

  • πŸ‡ΊπŸ‡ΈUnited States ethomas08 SF Bay Area

    Used comment 10 feedback to create rerolled patch for the 7.102 drupal core release.

Production build 0.71.5 2024