[wp-trac] [WordPress Trac] #37791: `Walker_Nav_Menu::start_el` accesses property of non-object and throws notice

WordPress Trac noreply at wordpress.org
Tue Aug 23 15:13:51 UTC 2016


#37791: `Walker_Nav_Menu::start_el` accesses property of non-object and throws
notice
--------------------------+-----------------------------
 Reporter:  schlessera    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Menus         |    Version:  4.6
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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:
 {{{#!php
     $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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37791>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list