-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Fix TypeError: Argument 1 passed to JsonResponse::setJson() must be of the type string, object given #39271
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
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
By passing |
@derrabus I'm okay to throw an InvalidArgument exception but IMO this part of code shouldn't throw TypeError exception. WDYT? |
Why not? We're expecting a string in that context and got What I do understand is that the message of the |
@derrabus found that there was a different kind of exception https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/HttpFoundation/Response.php#L403-L412 which was removed with type-hints. So I've added almost the same exception and message |
Right, we used that exception back in the PHP 5 days where we did not have |
BTW I have a strong feeling that the first argument of
Because it doesn't make a lot of sense to allow pass p.s. But I suppose it will be a BC break and shouldn't be in this PR. WDYT @derrabus ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the PR so far, just a minor suggestion.
You are right about |
Okay, so But this also tells me that we should apply your change to the 4.4 branch. Can you rebase? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just two CS issues from fabbot.
src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php
Outdated
Show resolved
Hide resolved
I think we need to add this to the
Apart from that, the PR looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR.
I agree, this is something that should be fixed. But a small BC break has snuck in :/
We need to fix it in another way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome.
I understand now and I like it =)
…tJson() must be of the type string, object given
Thank you @sidz. |
This PR fixes the type error when user set
null
as data in thenew JsonResponse(null, 200, [], true)
and true in the fourth argument to mark that value is json.