Make WordPress Core

Changeset 46128


Ignore:
Timestamp:
09/15/2019 11:05:31 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Code Modernisation: Introduce the spread operator in wp-includes/formatting.php.

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/formatting.php

    r46105 r46128  
    48374837 * @return string The formatted string.
    48384838 */
    4839 function wp_sprintf( $pattern ) {
    4840     $args      = func_get_args();
     4839function wp_sprintf( $pattern, ...$args ) {
    48414840    $len       = strlen( $pattern );
    48424841    $start     = 0;
     
    48684867            // Find numbered arguments or take the next one in order
    48694868            if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) {
    4870                 $arg      = isset( $args[ $matches[1] ] ) ? $args[ $matches[1] ] : '';
     4869                $index    = $matches[1] - 1; // 0-based array vs 1-based sprintf arguments.
     4870                $arg      = isset( $args[ $index ] ) ? $args[ $index ] : '';
    48714871                $fragment = str_replace( "%{$matches[1]}$", '%', $fragment );
    48724872            } else {
     4873                $arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : '';
    48734874                ++$arg_index;
    4874                 $arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : '';
    48754875            }
    48764876
Note: See TracChangeset for help on using the changeset viewer.