Problem/Motivation

PHP 7.4 produce notices when trying to access nonexistent array index. Those are displayed in Drupal DBlog:
"Notice: Trying to access array offset on value of type null..."

Steps to reproduce

Use Block Styles module with PHP 7.4

Proposed resolution

Check if array index is set before evaluating it.

CommentFileSizeAuthor
#5 3168455-5.patch1.06 KBt_d_d
#2 3168455-2.patch1.12 KBt_d_d
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

t_d_d created an issue. See original summary.

t_d_d’s picture

Status: Active » Needs review
FileSize
1.12 KB

patch with fix provided

arx-e’s picture

Isn't the second evaluation redundant?
Wouldn't it be simpler to leave just the isset evaluation alone like this?
if ( isset($style['theme']) ) {
instead of this
if (isset($style['theme']) && $style['theme']) {

t_d_d’s picture

I dont know if it is possible to have empty string there and if that would be a problem for theming, but i guess not. I just left second evaluation there to be sure not to change original behavior.

t_d_d’s picture

FileSize
1.06 KB

Ok, looks like only falsy thing ("0") that second condition will prevent is already prevented somewhere else so second conditon is most likely really redundant. New patch attached.

hatuhay’s picture

Status: Needs review » Fixed

  • hatuhay committed 91e9141 on 8.x-1.x authored by t_d_d
    Issue #3168455 by t_d_d: PHP 7.4 Notice: Trying to access array offset...

Status: Fixed » Closed (fixed)

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