From 4d3a84aa9fca1aa9d79649534e7312bdec85c166 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 12 Jul 2019 00:17:57 +0000 Subject: [PATCH] Code Modernisation: Introduce the spread operator in `wpdb::prepare()`. 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. Built from https://develop.svn.wordpress.org/trunk@45630 git-svn-id: http://core.svn.wordpress.org/trunk@45441 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/wp-db.php | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index aa93def4dd..11cf0d2aed 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45629'; +$wp_version = '5.3-alpha-45630'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 3c41943e55..46851b14fb 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1267,17 +1267,19 @@ class wpdb { * %f (float) * %s (string) * - * All placeholders MUST be left unquoted in the query string. A corresponding argument MUST be passed for each placeholder. + * All placeholders MUST be left unquoted in the query string. A corresponding argument + * MUST be passed for each placeholder. * - * For compatibility with old behavior, numbered or formatted string placeholders (eg, %1$s, %5s) will not have quotes - * added by this function, so should be passed with appropriate quotes around them for your usage. + * For compatibility with old behavior, numbered or formatted string placeholders (eg, %1$s, %5s) + * will not have quotes added by this function, so should be passed with appropriate quotes around + * them for your usage. * * Literal percentage signs (%) in the query string must be written as %%. Percentage wildcards (for example, * to use in LIKE syntax) must be passed via a substitution argument containing the complete LIKE string, these * cannot be inserted directly in the query string. Also see wpdb::esc_like(). * - * Arguments may be passed as individual arguments to the method, or as a single array containing all arguments. A combination - * of the two is not supported. + * Arguments may be passed as individual arguments to the method, or as a single array containing + * all arguments. A combination of the two is not supported. * * Examples: * $wpdb->prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d OR `other_field` LIKE %s", array( 'foo', 1337, '%bar' ) ); @@ -1287,12 +1289,15 @@ class wpdb { * @since 2.3.0 * * @param string $query Query statement with sprintf()-like placeholders - * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called with an array of arguments, - * or the first variable to substitute into the query's placeholders if being called with individual arguments. - * @param mixed ...$args further variables to substitute into the query's placeholders if being called wih individual arguments. + * @param array|mixed $args The array of variables to substitute into the query's placeholders + * if being called with an array of arguments, or the first variable + * to substitute into the query's placeholders if being called with + * individual arguments. + * @param mixed ...$args Further variables to substitute into the query's placeholders + * if being called with individual arguments. * @return string|void Sanitized query string, if there is a query to prepare. */ - public function prepare( $query, $args ) { + public function prepare( $query, ...$args ) { if ( is_null( $query ) ) { return; } @@ -1303,9 +1308,6 @@ class wpdb { _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9.0' ); } - $args = func_get_args(); - array_shift( $args ); - // If args were passed as an array (as in vsprintf), move them up. $passed_as_array = false; if ( is_array( $args[0] ) && count( $args ) == 1 ) {