#40332 closed enhancement (invalid)
Is passing arguments by reference in Walker_Nav_Menu methods needed?
| Reported by: | dingo_d | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Menus | Version: | 4.7.3 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: | performance |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@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.
class Reference_Test { public function pass_by_reference( &$output ) { $output .= ' : Passed By Reference'; } public function no_reference( $output ) { $output .= ' : No Reference'; } } $output = 'Start'; $test = new Reference_Test(); $test->pass_by_reference( $output ); $test->no_reference( $output ); echo $output; // Output is "Start : Passed By Reference"