Problem/Motivation

PHP 7.4 is producing the following notice in some pages of the site:
"Notice: Trying to access array offset on value of type null in _webform_client_form_rule_check() (line 2079 of /sites/all/modules/contrib/webform/webform.module)."

Steps to reproduce

Use the webform module 7.3.* with PHP 7.4

Proposed resolution

Check if the array index is set.

Other potential solution would be upgrading the module to 7.4.* as mentioned in the forum https://www.drupal.org/forum/support/post-installation/2020-07-02/notice..., but in order to avoid issues with the upgrade I'm creating this patch to fix this in a simpler way.

Issue fork webform-3199650

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joaopauloscho’s picture

Status: Active » Needs review
StatusFileSize
new1.13 KB
joaopauloscho’s picture

Assigned: joaopauloscho » Unassigned
avpaderno’s picture

Version: 7.x-3.30 » 7.x-3.x-dev
Status: Needs review » Needs work
yookoala’s picture

StatusFileSize
new1.44 KB

A different approach to patch the current issue. Should be more consistent to current behaviour.

yookoala’s picture

StatusFileSize
new1.44 KB

Patch updated.

liam morland’s picture

Status: Needs work » Needs review

I don't think the is_array($conditional_component) is needed.

Please put the fix into an issue fork.

yookoala’s picture

@Lian: Thanks for evaluating this.

The variable $conditional_component is created on line 2078:

$conditional_component = isset($component['extra']['conditional_component']) && isset($node->webform['components'][$component['extra']['conditional_component']]) ? $node->webform['components'][$component['extra']['conditional_component']] : NULL;

Logically speaking, the variable can be NULL instead of an array. And evaluating isset($array['key']), if $array is null, could raise "Unidentified Index with NULL value" warning in some PHP setup. So is_array($conditional_component) is a safety check before evaluating isset($conditional_component['cid']).

avpaderno’s picture

isset($conditional_component['cid']) will be FALSE even when the value of $conditional_component is NULL. It won't also raise any exception, or cause errors.

You can verify that with this code, which prints 0.

$array = NULL;
$test = (integer) isset($array["ggg"]);
echo $test, "\n";
yookoala’s picture

StatusFileSize
new1.32 KB

@kiamlaluno: Just tested. You are right. Since isset is a language construction, it does not evaluate the function parameter. So it does not trigger the warning. Just added a new patch (and a new commit to the issue fork) to simplify the code.

Thanks.

avpaderno’s picture

Status: Needs review » Needs work

The error shown in the dispatcher isn't much descriptive.

09:49:17 error: patch failed: webform.module:2076
09:49:17 error: webform.module: patch does not apply
09:49:17 Patch Error
09:49:17 The patch attempt returned an error. Error code: 1
09:49:17 Patch Failed to Apply
09:49:17 error: patch failed: webform.module:2076
09:49:17 error: webform.module: patch does not apply

yookoala’s picture

Maybe should squash the commits into a single patch. This system is quite confusing.

liam morland’s picture

Please put the patch into the issue fork. Let me know if you need help doing this.

yookoala’s picture

StatusFileSize
new1.42 KB

I have squashed the patch both here and on the issue fork. Please check.

  • yookoala committed fa54225 on 7.x-3.x
    Issue #3199650: Fix PHP 7.4 compatibility
    
    * Properly handle $...

liam morland’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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