Make WordPress Core

Changeset 51652


Ignore:
Timestamp:
08/23/2021 11:42:58 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Pass correct default value to http_build_query() in WP_Sitemaps_Provider::get_sitemap_url().

The WP_Sitemaps_Provider::get_sitemap_url() method calls the PHP native http_build_query() function, the second parameter of which is the optional $numeric_prefix parameter which expects a string.

A parameter being optional, however, does not automatically make it nullable.

As of PHP 8.1, passing null to a non-nullable PHP native function will generate a deprecation notice.

In this case, this function call yielded a http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated notice.

Changing the null to an empty string fixes this without a backward compatibility break.

This change is already covered by tests as 14 of the existing tests failed on these function calls when running the tests on PHP 8.1.

References:

Follow-up to [48470].

Props jrf.
See #53635.

File:
1 edited

Legend:

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

    r48470 r51652  
    161161
    162162                if ( ! $wp_rewrite->using_permalinks() ) {
    163                         $basename = '/?' . http_build_query( $params, null, '&' );
     163                        $basename = '/?' . http_build_query( $params, '', '&' );
    164164                }
    165165
Note: See TracChangeset for help on using the changeset viewer.