-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG]: Different behavior json_decode and \Phalcon\Helper\Json::decode() #14936
Comments
This is because the Phalcon uses the JSON_THROW_ON_ERROR constant in json_decode options But in my code I always use this constant |
JSON_THROW_ON_ERROR in the json_decode() is known. But in the phalcon, there is a problem with getJsonRawBody(), there we can not specify the json decode options. Nonetheless , by default, I think, the behavior of the json_decode and the \Phalcon\Helper\Json::decode() should be the same. |
As temporarily fix, you can override this method |
Well, even in plain PHP it is error: var_dump(json_decode(""));
echo json_last_error_msg();
|
but the result of Let me tell you what caused me to write Issue. In the project on Phalcon 3, there is a class that accepts So with the upgrade to Phalcon 4, the behavior has changed, now an error is issued. I temporarily replaced and it works :) but in essence - it should work the same P.S. I seem not the only one https://forum.phalcon.io/discussion/20587/getjsonrawbody-strange-behavior |
Fixed in 4.0.x branch. Thank you for the bug report, and for helping us make Phalcon better. |
Thanks guys! |
if you pass an empty value in the json_decode(), it will return null
but the \Phalcon\Helper\Json::decode("") throws out Exception:
as a result, early compatibility breaks $ this->request->getJsonRawBody()
What behavior will be correct?)
Thx
The text was updated successfully, but these errors were encountered: