-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpClient] toArray is a bad and wrong name for json #32481
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
Comments
See #31913 and #30499 (comment) for some more info (TLDR; it's about "array response bodies", not JSON per se) |
JSON stands for JavaScript Object Notation. No API should respond with anything else than an object and/or an array. Yes, this is a should. toArray works with conforming APIs, and will throw a well-defined exception when something else is returned. When this happens, one should use getContent() instead. |
Also, we're adding more |
Maybe |
I'm about naming. not else. (but parameter for return object will be fine too π ) |
it will always return an array, or error as such. That's exactly the main-feature of this method. |
Nope. It just do
Data can be simple "json encoded" string for example. Like |
see a few lines below :) symfony/src/Symfony/Component/HttpClient/Response/ResponseTrait.php Lines 160 to 162 in d3c17f2
|
Oooops, missed it ) |
Imagine that I got
true
response from API. That method do it right and return PHPtrue
(coz json_decode). But... TO ARRAY ? Istrue
IS ARRAY ? Or maybe123
is array also ? πAlso someone want to get PHP object instead array (preferences).
Maybe one more method like
getJson($throw = true, $asArray = true)
and deprecatetoArray
? πΈThe text was updated successfully, but these errors were encountered: