Code Modernisation: Introduce the spread operator in Walker.

Rather than relying `func_get_args()` to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

Props jrf.
See #47678.


git-svn-id: https://develop.svn.wordpress.org/trunk@45624 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-07-11 23:50:37 +00:00
parent 1963a00f83
commit 6c3ba83eb9

View File

@ -184,10 +184,10 @@ class Walker {
*
* @param array $elements An array of elements.
* @param int $max_depth The maximum hierarchical depth.
* @param mixed ...$args Optional additional arguments.
* @return string The hierarchical item output.
*/
public function walk( $elements, $max_depth ) {
$args = array_slice( func_get_args(), 2 );
public function walk( $elements, $max_depth, ...$args ) {
$output = '';
//invalid parameter or nothing to walk
@ -278,14 +278,14 @@ class Walker {
* @param int $max_depth The maximum hierarchical depth.
* @param int $page_num The specific page number, beginning with 1.
* @param int $per_page
* @param mixed ...$args Optional additional arguments.
* @return string XHTML of the specified page of elements
*/
public function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
if ( empty( $elements ) || $max_depth < -1 ) {
return '';
}
$args = array_slice( func_get_args(), 4 );
$output = '';
$parent_field = $this->db_fields['parent'];