-
Notifications
You must be signed in to change notification settings - Fork 23
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
Small json_encode() improvement suggestion #14
Comments
Hi @AnrDaemon. Thanks for suggesting that, but I was doing some performance tests comparing the proposed solution with the current implemented and the difference is not significative. I copied the class with some changes to allow override the Resuming each version by the latest version, comparing original options vs proposed options:
So, based on the results above, it doesn't increase the performance, except on 5.5 by a little. Also, changing the PS: I didn't include Thanks for your suggestion, but I guess we will pass on this one. |
Since json_encode options is a bit set, it cannot cause backward incompatibilities. |
The BC issue I mention is people expecting one output and receiving another. It can be fine for PHP, but can cause issues if they are using this output with another app in different language or using a different library. I'm planning to make changes on the library to allow the json options to be passed to the serialize method. Kind like I did on the demo in 3v4l. Allowing you to send the options that you want without breaking/extending anything. The default would be the options from the library. Thanks for saying it was an inspiration for you. It inspires us from sharing and contributing even more things. 👍 |
When I'm producing some output that is intended to be consumed by some foreign application, I'm trying to stick to standards as much as possible. If standard says "this is not recommended" or "this is optional", I read that as strictly forbidden, and so on. |
Instead of wasting CPU cycles in
JsonSerializer::calculateEncodeOptions()
, just use numeric value.1856 == JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION
or
1344 == JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION
The text was updated successfully, but these errors were encountered: