Warning: Trying to access array offset on value of type null in spammaster_form_validate() (line 564 of modules/contrib/spammaster/spammaster.module).

Created on 19 December 2023, 11 months ago
Updated 21 December 2023, 11 months ago

Problem/Motivation

After updating to version 2.3 I get this error in almost all pages with form:

Warning: Trying to access array offset on value of type null in spammaster_form_validate() (line 564 of modules/contrib/spammaster/spammaster.module).

Proposed resolution

Add an isset check in the the if statement like this:

    if (isset($form_state->getValue('field_email')[0]['value']) && NULL !== $form_state->getValue('field_email')[0]['value']) {
๐Ÿ› Bug report
Status

Fixed

Version

2.3

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡นItaly nessunluogo Tremestieri Etneo (CT)

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @nessunluogo
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    chetan 11 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !1fixed โ†’ (Open) created by chetan 11
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    Please check the attached solution in MR.

  • Status changed to RTBC 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly nessunluogo Tremestieri Etneo (CT)

    This is ok for me.
    Thanks!

  • Assigned to pedro-alves
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal pedro-alves

    Hi nessunluogo,

    Thanks for reporting. Are you by any chance using defunct PHP 5.x?

    Regarding your proposed solution to use isset... creates a fatal error:
    PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in /modules/spammaster/spammaster.module on line 564

    So... I'm thinking of replacing isset with !empty
    if (!empty($form_state->getValue('field_email')[0]['value']) && NULL !== $form_state->getValue('field_email')[0]['value']) {
    I will push version 2.4.

    Also thanks chetan 11. But there's a few more fixes we need to implement.

  • ๐Ÿ‡ต๐Ÿ‡นPortugal pedro-alves

    Hi nessunluogo,

    Other users brought to my attention that version 2.4 was packaged with version 2.3.
    For some reason drupal package manager gave error after uploading version 2.4 to drupal ftp and presented module version 2.3 as 2.4!!!
    I uploaded version 2.5 that looks correct now and should address your issue.
    When you have the time please test and post back.

    Sorry for any inconveniences.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly nessunluogo Tremestieri Etneo (CT)

    Hi pedro-alves, thank you for your reply.
    I'm on PHP 8.1 and understand why to use "null !== expression" as alternative to isset().

    I want to add that while trying to test the issue fork I rolled-back to the 2.3 and got no Warning but a WSOD as anonymous user. I'm not on the dev environment at the moment, but I'll check 2.5 and report ASAP.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly nessunluogo Tremestieri Etneo (CT)

    Updated to 2.5 and I get this couple of warnings:

    Warning: Undefined variable $spammasteremail in spammaster_form_validate() (line 575 of modules/contrib/spammaster/spammaster.module).
    ...
    Warning: Undefined variable $spammasteremail in spammaster_form_validate() (line 614 of modules/contrib/spammaster/spammaster.module).

    As far as I can tell, this can be fixed setting the variable to null before the if section (eg. line 565).

    Besides this, I get a WSOD on anonymous user with a GuzzleHttp\Exception\RequestException in my local environment, but this desn't look to be related to this issue, so I'm going to open a new one.

  • ๐Ÿ‡ต๐Ÿ‡นPortugal pedro-alves

    oh I see, both warnings (line 575 and 614) are a typo related to previous fix.
    line 575:
    if (!empty($spammasteremail) || is_array($spammasteremail)) {
    should be if empty:
    if (empty($spammasteremail) || is_array($spammasteremail)) {
    Fixed in version 2.6.

    Regarding "WSOD on anonymous" please do open a new ticket if related to the module.

    Thank you again.

  • Status changed to RTBC 11 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly nessunluogo Tremestieri Etneo (CT)

    Nevermind, couldn't reproduce WSOD issue.

  • Status changed to Fixed 11 months ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal pedro-alves

    Great. Closing this one now.
    Thanks again for reporting.

  • Status changed to Fixed 11 months ago
  • ๐Ÿ‡ต๐Ÿ‡นPortugal pedro-alves
Production build 0.71.5 2024