-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[11.x] Add array response type #54160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Add array response type #54160
Conversation
It looks like I mistakenly removed this in a PR a while ago. You are correct about this possibly returning an array |
No problem, I just wanted to know if it would be possible to introduce this annotation here, because I have a file showing an error in my project. |
OP is correct here. However, given the method name is literally |
Do you really want var_dump((object)json_decode('5')); to end up as object(stdClass)#1 (1) {
["scalar"]=>
int(5)
} or var_dump((object)json_decode('[5]')); to end up as object(stdClass)#1 (1) {
["0"]=>
int(5)
} which would have to accessed as
I'm not sure if—even if it seems plausible at first thought—manipulating the input is the right way to go. Passing |
Fair, the scalar example results in nonsense. But yeah, I'd totally expect As you said, it all boils down to:
But the method is here now and I believe it should do what it indicates. Tricky. |
That's why I'd say, always returning an object can be the solution. And changing the annotation as it is done in this PR by @MagicalStrangeQuark is the only thing we can do right now about this with the method itself. One additional thing we can do, is adding a warning to the docs Deprecating the method and creating a new one with the name |
Sorry I can't add a return type of array to a method named "object". Just too embarrassing. 😅 |
@taylorotwell Do you ever read the discussion below a PR? If you did, you wouldn't be saying this. |
Update object method annotation in Illuminate\Http\Client\Response to include array as a possible return type from json_decode.
I’m reopening this PR because I have a file using an API that returns an array of objects. The current method assumes only objects are returned, which is causing an error in my pipeline.
For example, if `$this->body() returns something like:
The actual implementation of object allows an array as response
Therefore, the annotation needs to be updated to reflect that an array can also be returned.