Make WordPress Core


Ignore:
Timestamp:
12/08/2022 05:26:17 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r54733 r54950  
    12451245         * @see esc_sql()
    12461246         *
    1247          * @param string $string
     1247         * @param string $data
    12481248         * @return string
    12491249         */
    1250         public function _weak_escape( $string ) {
     1250        public function _weak_escape( $data ) {
    12511251                if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
    12521252                        _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
    12531253                }
    1254                 return addslashes( $string );
     1254                return addslashes( $data );
    12551255        }
    12561256
     
    12631263         * @see mysql_real_escape_string()
    12641264         *
    1265          * @param string $string String to escape.
     1265         * @param string $data String to escape.
    12661266         * @return string Escaped string.
    12671267         */
    1268         public function _real_escape( $string ) {
    1269                 if ( ! is_scalar( $string ) ) {
     1268        public function _real_escape( $data ) {
     1269                if ( ! is_scalar( $data ) ) {
    12701270                        return '';
    12711271                }
     
    12731273                if ( $this->dbh ) {
    12741274                        if ( $this->use_mysqli ) {
    1275                                 $escaped = mysqli_real_escape_string( $this->dbh, $string );
     1275                                $escaped = mysqli_real_escape_string( $this->dbh, $data );
    12761276                        } else {
    1277                                 $escaped = mysql_real_escape_string( $string, $this->dbh );
     1277                                $escaped = mysql_real_escape_string( $data, $this->dbh );
    12781278                        }
    12791279                } else {
     
    12841284                        _doing_it_wrong( $class, sprintf( __( '%s must set a database connection for use with escaping.' ), $class ), '3.6.0' );
    12851285
    1286                         $escaped = addslashes( $string );
     1286                        $escaped = addslashes( $data );
    12871287                }
    12881288
     
    13551355         * @since 2.3.0
    13561356         *
    1357          * @param string $string String to escape.
    1358          */
    1359         public function escape_by_ref( &$string ) {
    1360                 if ( ! is_float( $string ) ) {
    1361                         $string = $this->_real_escape( $string );
     1357         * @param string $data String to escape.
     1358         */
     1359        public function escape_by_ref( &$data ) {
     1360                if ( ! is_float( $data ) ) {
     1361                        $data = $this->_real_escape( $data );
    13621362                }
    13631363        }
     
    31623162         * @since 4.2.0
    31633163         *
    3164          * @param string $string String to check.
     3164         * @param string $input_string String to check.
    31653165         * @return bool True if ASCII, false if not.
    31663166         */
    3167         protected function check_ascii( $string ) {
     3167        protected function check_ascii( $input_string ) {
    31683168                if ( function_exists( 'mb_check_encoding' ) ) {
    3169                         if ( mb_check_encoding( $string, 'ASCII' ) ) {
     3169                        if ( mb_check_encoding( $input_string, 'ASCII' ) ) {
    31703170                                return true;
    31713171                        }
    3172                 } elseif ( ! preg_match( '/[^\x00-\x7F]/', $string ) ) {
     3172                } elseif ( ! preg_match( '/[^\x00-\x7F]/', $input_string ) ) {
    31733173                        return true;
    31743174                }
Note: See TracChangeset for help on using the changeset viewer.