Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#37791 closed defect (bug) (duplicate)

`Walker_Nav_Menu::start_el` accesses property of non-object and throws notice

Reported by: schlessera's profile schlessera Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

The method start_el in the Walker_Nav_Menu class gets as its $args argument an array of arguments that were passed to the wp_nav_menu() function (https://developer.wordpress.org/reference/functions/wp_nav_menu/).

On lines 183-187, this array is accessed as an object, though:

    $item_output = $args->before;
    $item_output .= '<a'. $attributes .'>';
    $item_output .= $args->link_before . $title . $args->link_after;
    $item_output .= '</a>';
    $item_output .= $args->after;

This bit of code throws four PHP notices: NOTICE: TRYING TO GET PROPERTY OF NON-OBJECT IN [...]/WP-INCLUDES/CLASS-WALKER-NAV-MENU.PHP ON LINE 183

Assuming that the doc blocks throughout that method are correct, the four calls above should be transformed into an array access.

Attachments (3)

37791-1.diff (769 bytes) - added by schlessera 8 years ago.
37791-2.diff (1.0 KB) - added by schlessera 8 years ago.
replaces file 37791-1.diff
37791-3.diff (1.2 KB) - added by schlessera 8 years ago.
replaces file 37791-2.diff

Download all attachments as: .zip

Change History (7)

@schlessera
8 years ago

@schlessera
8 years ago

replaces file 37791-1.diff

@schlessera
8 years ago

replaces file 37791-2.diff

#2 @schlessera
8 years ago

  • Keywords has-patch added

Assuming that the doc blocks throughout that method are correct, the four calls above should be transformed into an array access.

Well, just found out this is not the case.

I attached a new patch that fixes the specific issue by converting an eventual object into an array.

There should be a consensus on how to pass arguments around in this context, and all the methods then need to conform to that. This would avoid unnecessary conversions and unexpected notices.

Please ignore the first two patches, 37791-3.diff should be the good one.

#3 @peterwilsoncc
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Following your extra notes, I'm going to label this as a dupe of #24587.

There was some discussion on the ticket about converting the object to an array breaking back-compat for filters expecting an object.

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.


8 years ago

Note: See TracTickets for help on using tickets.