From 6c70fad9d74b4220c443a88f158d9175174fbf36 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Sun, 22 Aug 2021 22:02:28 +0200
Subject: [PATCH] PHP 8.1: WP_Sitemaps_Provider::get_sitemap_url(): fix
deprecation notice (TRAC 53635)
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 BC-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.
Refs:
* https://www.php.net/manual/en/function.http-build-query.php
* https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
---
src/wp-includes/sitemaps/class-wp-sitemaps-provider.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wp-includes/sitemaps/class-wp-sitemaps-provider.php b/src/wp-includes/sitemaps/class-wp-sitemaps-provider.php
index 3440f62b34..e77681d721 100644
a
|
b
|
abstract class WP_Sitemaps_Provider { |
160 | 160 | ); |
161 | 161 | |
162 | 162 | if ( ! $wp_rewrite->using_permalinks() ) { |
163 | | $basename = '/?' . http_build_query( $params, null, '&' ); |
| 163 | $basename = '/?' . http_build_query( $params, '', '&' ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | return home_url( $basename ); |