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.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 0001-Issue-3199650-Fix-PHP-7.4-compatibility.patch | 1.42 KB | yookoala |
Issue fork webform-3199650
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:
- 3199650-fix-php74-notice
changes, plain diff MR !17
- 3199650-php-7.4-notice
changes, plain diff MR !15
Comments
Comment #2
joaopauloscho commentedComment #3
joaopauloscho commentedComment #4
avpadernoComment #5
yookoala commentedA different approach to patch the current issue. Should be more consistent to current behaviour.
Comment #6
yookoala commentedPatch updated.
Comment #7
liam morlandI don't think the
is_array($conditional_component)is needed.Please put the fix into an issue fork.
Comment #9
yookoala commented@Lian: Thanks for evaluating this.
The variable
$conditional_componentis created on line 2078:Logically speaking, the variable can be NULL instead of an array. And evaluating
isset($array['key']), if$arrayis null, could raise "Unidentified Index with NULL value" warning in some PHP setup. Sois_array($conditional_component)is a safety check before evaluatingisset($conditional_component['cid']).Comment #10
avpadernoisset($conditional_component['cid'])will beFALSEeven when the value of$conditional_componentisNULL. It won't also raise any exception, or cause errors.You can verify that with this code, which prints 0.
Comment #11
yookoala commented@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.
Comment #12
avpadernoThe error shown in the dispatcher isn't much descriptive.
Comment #13
yookoala commentedMaybe should squash the commits into a single patch. This system is quite confusing.
Comment #14
liam morlandPlease put the patch into the issue fork. Let me know if you need help doing this.
Comment #15
yookoala commentedI have squashed the patch both here and on the issue fork. Please check.
Comment #19
liam morland