Skip to content

Commit

Permalink
PHP 8.1: fix deprecation notices in Requests_Transport_cURL
Browse files Browse the repository at this point in the history
The `Requests_Transport_cURL:;setup_handle()` and `Requests_Transport_cURL::format_get()` methods, both call 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, both these function calls 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 15 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
  • Loading branch information
jrfnl committed Jun 21, 2021
1 parent c637258 commit ba05144
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ protected function setup_handle($url, $headers, $data, $options) {
$data = '';
}
elseif (!is_string($data)) {
$data = http_build_query($data, null, '&');
$data = http_build_query($data, '', '&');
}
}

Expand Down Expand Up @@ -527,7 +527,7 @@ protected static function format_get($url, $data) {
$query = $url_parts['query'];
}

$query .= '&' . http_build_query($data, null, '&');
$query .= '&' . http_build_query($data, '', '&');
$query = trim($query, '&');

if (empty($url_parts['query'])) {
Expand Down

0 comments on commit ba05144

Please sign in to comment.