amphp / http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.

Home Page:https://amphp.org/http-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BC break: v5 `Request::setBody` should accept `null`

Bilge opened this issue · comments

commented

v5 Request::setBody should accept null because it did in v4. Also, WTF is up with int and float?

http-client/src/Request.php

Lines 222 to 230 in 92b60c1

public function setBody(string|int|float|RequestBody $body): void
{
$this->body = match (true) {
\is_string($body) => new StringBody($body),
\is_scalar($body) => new StringBody(\var_export($body, true)),
$body instanceof RequestBody => $body,
default => throw new \TypeError("Invalid body type: " . \gettype($body)),
};
}

It does accept null in #322. Please provide any feedback regarding the body API there.