Make WordPress Core

Changeset 63511


Ignore:
Timestamp:
09/07/2026 05:33:42 AM (6 weeks ago)
Author:
westonruter
Message:

Code Quality: Improve typing for wp_array_slice_assoc().

The @param and @return tags have documented a bare array since the function was introduced in r15574, so nothing was known about the slice it returns. They now describe the string-keyed arrays the function accepts, PHPStan generics bind the returned key set to the $keys argument so that a call passing a known list of keys resolves to those keys rather than to string. The signature also gains a native array return type.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13417.
Follow-up to r15574.

See #65817, #65860.

File:
1 edited

Legend:

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

    r63510 r63511  
    51285128 * @since 3.1.0
    51295129 *
    5130  * @param array $input_array The original array.
    5131  * @param array $keys        The list of keys.
    5132  * @return array The array slice.
    5133  */
    5134 function wp_array_slice_assoc( $input_array, $keys ) {
     5130 * @param array<string, mixed> $input_array The original array.
     5131 * @param string[]             $keys        The list of keys.
     5132 * @return array<string, mixed> The array slice.
     5133 *
     5134 * @phpstan-template TKey of string
     5135 * @phpstan-template TValue
     5136 * @phpstan-param array<string, TValue> $input_array
     5137 * @phpstan-param array<TKey> $keys
     5138 * @phpstan-return array<TKey, TValue>
     5139 */
     5140function wp_array_slice_assoc( $input_array, $keys ): array {
    51355141        $slice = array();
    51365142
Note: See TracChangeset for help on using the changeset viewer.