Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#47524 closed defect (bug) (fixed)

Predefined value of param is wrong in \Walker_Nav_Menu::start_lvl

Reported by: trasweb's profile trasweb Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Menus Keywords:
Focuses: docs Cc:

Description

Signature of start_lvl in Walker_Nav_Menu class is:

<?php
public function start_lvl( &$output, $depth = 0, $args = array() )

In this, $args is array.

However, $args is stdClass as we can see in comment of that method:

<?php
/*
...
* @param string   $output Used to append additional content (passed by reference).
* @param int      $depth  Depth of menu item. Used for padding.
* @param stdClass $args   An object of wp_nav_menu() arguments.
...
*/

Maybe null should be a better predefined value.

Change History (5)

#1 follow-up: @mukesh27
5 years ago

  • Focuses docs added

Hi @trasweb, welcome to WordPress Trac! Thanks for the ticket.

Can we use below doc changes

* @param stdClass $args An object of wp_nav_menu() arguments.

Replace to

* @param array $args An array of arguments. @see wp_nav_menu()

#2 in reply to: ↑ 1 @trasweb
5 years ago

Hi, @mukesh27. You're welcome

I think that is not good option. To that method, it's passed $args as an object. So that, comment is perfect. Predetermined value is the wrong.

Replying to mukesh27:

Hi @trasweb, welcome to WordPress Trac! Thanks for the ticket.

Can we use below doc changes

* @param stdClass $args An object of wp_nav_menu() arguments.

Replace to

* @param array $args An array of arguments. @see wp_nav_menu()

#3 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Previously: #24587, [38559].

#4 @SergeyBiryukov
5 years ago

Initially I thought changing this would cause "Declaration must be compatible" errors in PHP 7+, but apparently this only happens when removing parameters in subclasses or making them required. In my testing, changing default parameter type is fine.

#5 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 45537:

Menus: Set better default for $args parameter in Walker_Nav_Menu methods, to match the documented parameter type.

Props trasweb.
Fixes #47524.

Note: See TracTickets for help on using tickets.