Problem/Motivation

Notice: Trying to access array offset on value of type bool in menu_breadcrumb_init() (line 314 of .../menu_breadcrumb/menu_breadcrumb.module).

Steps to reproduce

function menu_breadcrumb_init() {
  $is_front = drupal_is_front_page();
  if (variable_get('menu_breadcrumb_determine_menu', 1) && !$is_front) {
    // Find the set of menus containing a link for the current page.
    $menu_item = menu_get_item();
    $result = db_query("SELECT mlid, menu_name FROM {menu_links} WHERE link_path = :menu_item", array(':menu_item' => $menu_item['href']));

menu_get_item() can return false here, which causes the error.

Proposed resolution

Add a check and return early in this case.

Comments

solideogloria created an issue. See original summary.

solideogloria’s picture

Status: Active » Needs review
StatusFileSize
new1015 bytes
solideogloria’s picture

Issue summary: View changes
bceyssens’s picture

Seems to do the trick. +1

justinreynolds’s picture

this fixes the issue for me as well on php 7.4.18.

xurizaemon’s picture

StatusFileSize
new1.23 KB

Thanks solideogloria, this looks good and should work AFAICT.

I'm unsure though about return false - is that what we should do from a hook_init() implementation?

None of core's hook_init() implementations return values in any case.

I don't believe the return codes are used (_drupal_bootstrap_full()) and return false suggests the return value is meaningful, so IMO return; would be more correct with the same results.

solideogloria’s picture

Status: Needs review » Reviewed & tested by the community
vladimiraus’s picture

Thanks for the commit. Applies and works!

  • xurizaemon committed c3f4827 on 7.x-1.x
    Issue #3199016 by solideogloria, xurizaemon: PHP 7.4 error if...
xurizaemon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all! Committed to 7.x-1.x.

Status: Fixed » Closed (fixed)

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