Problem/Motivation

Starting with PHP 7.4, " Trying to use values of type null, bool, int, float or resource as an array (such as $null["key"]) will now generate a notice.". I updated to PHP 7.4 this week, and now I'm seeing those notices from menu.inc in line 2598.

    $end = end($active_trail);
    if ($item['href'] == $end['href']) {

I believe that $end may be FALSE at this point, or at any rate, $active_trail is not an array.

Proposed resolution

Check for is_array($end). See attached patch.

CommentFileSizeAuthor
menu.inc_.patch441 bytesennorehling

Comments

ennorehling created an issue. See original summary.

ennorehling’s picture

Issue summary: View changes
alex.bukach’s picture

Status: Active » Needs review
izmeez’s picture

izmeez’s picture

Status: Needs review » Reviewed & tested by the community

Changing status to RTBC. The patch is simple, looks good and fixes the problem. Thanks.

  • mcdruid committed ee42dea on 7.x
    Issue #3175678 by ennorehling: Trying to access array offset on value of...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed

I hesitated a little here as I'm not entirely sure how we'd end up with a non-array element in the $active_trail unless perhaps something broken happens in the drupal_alter() preceding this change.

We don't want to endlessly add checks to "babysit broken code" outside of core.

However, this seems pretty harmless.

Thank you!

Status: Fixed » Closed (fixed)

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