Make WordPress Core


Ignore:
Timestamp:
09/07/2026 11:14:20 PM (17 hours ago)
Author:
westonruter
Message:

Code Quality: Improve typing for wp_parse_args().

Both the parameters and the return value have been documented as a bare array since the function entered trunk in r5234. They now describe the string-keyed arrays it is used with, and the signature gains a native array return type. Every caller treats those keys as strings, but the function cannot guarantee it, since get_object_vars() reports a numeric-string property under an integer key and parse_str() reads 0=a as one, so the @phpstan-return records what can actually come back.

Developed in https://github.com/WordPress/wordpress-develop/pull/13430.
Follow-up to r5234, r47429.

See #65817, #65860.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpstan/baselines/argument.type.neon

    r63510 r63522  
    11301130                        path: ../../../src/wp-includes/pluggable.php
    11311131                -
    1132                         message: '#^Parameter \#1 \$args of function get_pages expects array\{child_of\?\: int, sort_order\?\: string, sort_column\?\: string, hierarchical\?\: bool, exclude\?\: array\<int\>, include\?\: array\<int\>, meta_key\?\: string, meta_value\?\: string, \.\.\., \.\.\.\}\|string, non\-empty\-array given\.$#'
     1132                        message: '#^Parameter \#1 \$args of function get_pages expects array\{child_of\?\: int, sort_order\?\: string, sort_column\?\: string, hierarchical\?\: bool, exclude\?\: array\<int\>, include\?\: array\<int\>, meta_key\?\: string, meta_value\?\: string, \.\.\., \.\.\.\}\|string, non\-empty\-array\<mixed\> given\.$#'
    11331133                        identifier: argument.type
    11341134                        count: 1
     
    12501250                        path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php
    12511251                -
     1252                        message: '#^Parameter \#1 \$args of function wp_parse_args expects array\<string, mixed\>\|object\|string, list\<array\> given\.$#'
     1253                        identifier: argument.type
     1254                        count: 1
     1255                        path: ../../../src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
     1256                -
    12521257                        message: '#^Parameter \#2 \$value of method WP_HTTP_Response\:\:header\(\) expects string, int given\.$#'
    12531258                        identifier: argument.type
Note: See TracChangeset for help on using the changeset viewer.