Make WordPress Core

Changeset 55136


Ignore:
Timestamp:
01/25/2023 01:38:59 AM (15 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Allow some parameters with reserved keywords in wp-includes/compat.php.

Parameter names for PHP polyfills in WordPress core need to 100% match the native PHP parameter names. Otherwise using named parameters with those functions could cause fatal errors for installations where the polyfills kick in.

This commit adds inline comments instructing PHPCS to ignore parameters with reserved keywords in the affected functions that should not be renamed:

  • $string parameter in mb_substr() and mb_strlen()
  • $array parameter in array_key_first() and array_key_last()

This resolves a few WPCS warnings along the lines of:

It is recommended not to use reserved keyword "string" as function parameter name. Found: $string

Follow-up to [7140], [10707], [17603], [17621], [32114], [52038], [53365].

Props jrf.
See #56788, #56791.

File:
1 edited

Legend:

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

    r54855 r55136  
    5757     * @return string Extracted substring.
    5858     */
    59     function mb_substr( $string, $start, $length = null, $encoding = null ) {
     59    function mb_substr( $string, $start, $length = null, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
    6060        return _mb_substr( $string, $start, $length, $encoding );
    6161    }
     
    149149     * @return int String length of `$string`.
    150150     */
    151     function mb_strlen( $string, $encoding = null ) {
     151    function mb_strlen( $string, $encoding = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound
    152152        return _mb_strlen( $string, $encoding );
    153153    }
     
    394394     *                         is not empty; `null` otherwise.
    395395     */
    396     function array_key_first( array $array ) {
     396    function array_key_first( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
    397397        foreach ( $array as $key => $value ) {
    398398            return $key;
     
    414414     *.                        is not empty; `null` otherwise.
    415415     */
    416     function array_key_last( array $array ) {
     416    function array_key_last( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
    417417        if ( empty( $array ) ) {
    418418            return null;
Note: See TracChangeset for help on using the changeset viewer.