TLDR

Background / history

In some places we need to check if an array key starts with '#', which has a special meaning in render elements.
Currently we mostly do this with $key !== '' && $key[0] === '#'.

Problem

The condition causes a warning in PHP 7.4+ if the key is an integer:

Notice: Trying to access array offset on value of type int in arrayStripDangerousKeysRecursive() (line 75 of /[..]/cfrplugin/src/Util/DataUtil.php).

Steps to reproduce

Not sure, I did this with some custom code :)

Solution / Proposed change

Make the condition more robust, like in core element_children() or element_properties():

    if (is_int($key) || $key === '' || $key[0] !== '#') {

Risks

Not really. The proposed code still works in older PHP versions.

Comments

donquixote created an issue. See original summary.

  • donquixote committed eb437c6 on 7.x-2.x
    Issue #3270010 by donquixote: PHP 7.4+: Avoid array offset on integer...
donquixote’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.