Skip to content

Commit

Permalink
PHP 8.1: fix deprecation warnings / http_build_query()
Browse files Browse the repository at this point in the history
This fixes an issue with a call to 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 composer#2 ($numeric_prefix) of type string is deprecated` notice.

Changing the `null` to an empty string fixes this without BC-break.

Fixes nearly all deprecation warnings found when running the tests.

Refs:
* https://www.php.net/manual/en/function.http-build-query.php
* https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
  • Loading branch information
jrfnl committed Nov 29, 2021
1 parent d0f43ef commit 2b38cfd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tool/QueryBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ trait QueryBuilderTrait
*/
protected function buildQueryString(array $params)
{
return http_build_query($params, null, '&', \PHP_QUERY_RFC3986);
return http_build_query($params, '', '&', \PHP_QUERY_RFC3986);
}
}

0 comments on commit 2b38cfd

Please sign in to comment.