#37791 closed defect (bug) (duplicate)
`Walker_Nav_Menu::start_el` accesses property of non-object and throws notice
Reported by: | 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)
Change History (7)
#2
@
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
@
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.
Related: #18232, #24587, #37136.