Skip to content

Commit

Permalink
Code Modernisation: Introduce the spread operator in `wp-includes/for…
Browse files Browse the repository at this point in the history
…matting.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.

git-svn-id: https://develop.svn.wordpress.org/trunk@46128 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 15, 2019
1 parent 3ae54e8 commit cb1f496
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4836,8 +4836,7 @@ function wp_pre_kses_less_than_callback( $matches ) {
* @param mixed ...$args Arguments to be formatted into the $pattern string.
* @return string The formatted string.
*/
function wp_sprintf( $pattern ) {
$args = func_get_args();
function wp_sprintf( $pattern, ...$args ) {
$len = strlen( $pattern );
$start = 0;
$result = '';
Expand Down Expand Up @@ -4867,11 +4866,12 @@ function wp_sprintf( $pattern ) {
if ( $pattern[ $start ] == '%' ) {
// Find numbered arguments or take the next one in order
if ( preg_match( '/^%(\d+)\$/', $fragment, $matches ) ) {
$arg = isset( $args[ $matches[1] ] ) ? $args[ $matches[1] ] : '';
$index = $matches[1] - 1; // 0-based array vs 1-based sprintf arguments.
$arg = isset( $args[ $index ] ) ? $args[ $index ] : '';
$fragment = str_replace( "%{$matches[1]}$", '%', $fragment );
} else {
++$arg_index;
$arg = isset( $args[ $arg_index ] ) ? $args[ $arg_index ] : '';
++$arg_index;
}

/**
Expand Down

0 comments on commit cb1f496

Please sign in to comment.