Code Modernization: Rename parameters that use reserved keywords in wp-includes/class-wpdb.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit:
* Renames the `$string` parameter to `$data` in:
 * `wpdb::_weak_escape()`
 * `wpdb::_real_escape()`
 * `wpdb::escape_by_ref()`
* Renames the `$string` parameter to `$input_string` in `wpdb::check_ascii()`.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54950


git-svn-id: http://core.svn.wordpress.org/trunk@54502 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-12-08 17:28:15 +00:00
parent afab4aa575
commit 8c03cb5df8
2 changed files with 18 additions and 18 deletions

View File

@ -1244,14 +1244,14 @@ class wpdb {
* @see wpdb::prepare()
* @see esc_sql()
*
* @param string $string
* @param string $data
* @return string
*/
public function _weak_escape( $string ) {
public function _weak_escape( $data ) {
if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
_deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
}
return addslashes( $string );
return addslashes( $data );
}
/**
@ -1262,19 +1262,19 @@ class wpdb {
* @see mysqli_real_escape_string()
* @see mysql_real_escape_string()
*
* @param string $string String to escape.
* @param string $data String to escape.
* @return string Escaped string.
*/
public function _real_escape( $string ) {
if ( ! is_scalar( $string ) ) {
public function _real_escape( $data ) {
if ( ! is_scalar( $data ) ) {
return '';
}
if ( $this->dbh ) {
if ( $this->use_mysqli ) {
$escaped = mysqli_real_escape_string( $this->dbh, $string );
$escaped = mysqli_real_escape_string( $this->dbh, $data );
} else {
$escaped = mysql_real_escape_string( $string, $this->dbh );
$escaped = mysql_real_escape_string( $data, $this->dbh );
}
} else {
$class = get_class( $this );
@ -1283,7 +1283,7 @@ class wpdb {
/* translators: %s: Database access abstraction class, usually wpdb or a class extending wpdb. */
_doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), '3.6.0' );
$escaped = addslashes( $string );
$escaped = addslashes( $data );
}
return $this->add_placeholder_escape( $escaped );
@ -1354,11 +1354,11 @@ class wpdb {
*
* @since 2.3.0
*
* @param string $string String to escape.
* @param string $data String to escape.
*/
public function escape_by_ref( &$string ) {
if ( ! is_float( $string ) ) {
$string = $this->_real_escape( $string );
public function escape_by_ref( &$data ) {
if ( ! is_float( $data ) ) {
$data = $this->_real_escape( $data );
}
}
@ -3161,15 +3161,15 @@ class wpdb {
*
* @since 4.2.0
*
* @param string $string String to check.
* @param string $input_string String to check.
* @return bool True if ASCII, false if not.
*/
protected function check_ascii( $string ) {
protected function check_ascii( $input_string ) {
if ( function_exists( 'mb_check_encoding' ) ) {
if ( mb_check_encoding( $string, 'ASCII' ) ) {
if ( mb_check_encoding( $input_string, 'ASCII' ) ) {
return true;
}
} elseif ( ! preg_match( '/[^\x00-\x7F]/', $string ) ) {
} elseif ( ! preg_match( '/[^\x00-\x7F]/', $input_string ) ) {
return true;
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-54949';
$wp_version = '6.2-alpha-54950';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.