Skip to content

Commit b2300b1

Browse files
committed
TRAC 53635 | PHP 8.1: wp_parse_str() - fix handling of null
Fixes `parse_str(): Passing null to parameter #1 ($string) of type string is deprecated` notices on PHP 8.1. Impact: 311 of the pre-existing tests are affected by this issue.
1 parent adb1835 commit b2300b1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/wp-includes/formatting.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4944,7 +4944,13 @@ function map_deep( $value, $callback ) {
49444944
* @param array $array Variables will be stored in this array.
49454945
*/
49464946
function wp_parse_str( $string, &$array ) {
4947-
parse_str( $string, $array );
4947+
if ( ! isset( $array ) ) {
4948+
$array = array();
4949+
}
4950+
4951+
if ( is_scalar( $string ) ) {
4952+
parse_str( $string, $array );
4953+
}
49484954

49494955
/**
49504956
* Filters the array of variables derived from a parsed string.

0 commit comments

Comments
 (0)