#40332 closed enhancement (invalid)
Is passing arguments by reference in Walker_Nav_Menu methods needed?
Reported by: | dingo_d | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7.3 |
Component: | Menus | Keywords: | |
Focuses: | performance | Cc: |
Description
From what I've read, since PHP 5 objects are automatically passed by reference, and in the Walker_Nav_Menu
class we have methods that have arguments that are passed by reference like
public function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
$output .= "{$n}{$indent}<ul class=\"sub-menu\">{$n}";
}
So my question is: is this necessary? Especially given the fact that wordpress.org recommends the users to install it on PHP7 or greater.
Is this because of backwards compatibility or?
Change History (2)
Note: See
TracTickets for help on using
tickets.
@dingo_bastard thanks for the ticket! The pass by reference operator allows the function to modify the passed variable without returning it.
See the example below.