WordPress.org

Make WordPress Core

Changeset 45624


Ignore:
Timestamp:
07/11/2019 11:50:37 PM (4 months ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-walker.php

    r42343 r45624  
    185185     * @param array $elements  An array of elements.
    186186     * @param int   $max_depth The maximum hierarchical depth.
     187     * @param mixed ...$args   Optional additional arguments.
    187188     * @return string The hierarchical item output.
    188189     */
    189     public function walk( $elements, $max_depth ) {
    190         $args   = array_slice( func_get_args(), 2 );
     190    public function walk( $elements, $max_depth, ...$args ) {
    191191        $output = '';
    192192
     
    277277     * @param array $elements
    278278     * @param int   $max_depth The maximum hierarchical depth.
    279      * @param int   $page_num The specific page number, beginning with 1.
     279     * @param int   $page_num  The specific page number, beginning with 1.
    280280     * @param int   $per_page
     281     * @param mixed ...$args   Optional additional arguments.
    281282     * @return string XHTML of the specified page of elements
    282283     */
    283     public function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
     284    public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
    284285        if ( empty( $elements ) || $max_depth < -1 ) {
    285286            return '';
    286287        }
    287288
    288         $args   = array_slice( func_get_args(), 4 );
    289289        $output = '';
    290290
Note: See TracChangeset for help on using the changeset viewer.