Laravel Version
13.8.0
PHP Version
8.5.5
Database Driver & Version
No response
Description
A call to Illuminate\Http\Client\Response#json(default: []) does not respect the passed in default value. In other words: if the result of the aforementioned call is null this will be the value that will be returned instead of []. This is not logical in my opinion.
Whether this is a bug or not is perhaps debatable. From my (API consumer) perspective it is at least, as it doesn't make sense that passing in a key argument does respect the passed in default. I would at least expect it to be noted in the HTTP client documentation somewhere.
A fix seems easy enough: just replace return $this->decoded; with return $this->decoded ?? $default; here. Although you could argue that this will perhaps introduce a breaking change.
Steps To Reproduce
$response = Http::get(...);
// Assuming there is no response payload this returns `null` instead of `[]`, which doesn't seem logical
$response->json(default: []);
Laravel Version
13.8.0
PHP Version
8.5.5
Database Driver & Version
No response
Description
A call to
Illuminate\Http\Client\Response#json(default: [])does not respect the passed in default value. In other words: if the result of the aforementioned call isnullthis will be the value that will be returned instead of[]. This is not logical in my opinion.Whether this is a bug or not is perhaps debatable. From my (API consumer) perspective it is at least, as it doesn't make sense that passing in a key argument does respect the passed in default. I would at least expect it to be noted in the HTTP client documentation somewhere.
A fix seems easy enough: just replace
return $this->decoded;withreturn $this->decoded ?? $default;here. Although you could argue that this will perhaps introduce a breaking change.Steps To Reproduce