Skip to content
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

Fix json_decode problem #1005

Merged
merged 2 commits into from
Dec 10, 2015
Merged

Fix json_decode problem #1005

merged 2 commits into from
Dec 10, 2015

Conversation

theDisco
Copy link
Contributor

@theDisco theDisco commented Dec 9, 2015

As discussed in #1003 here is the PR that should at least make elastica to work properly when bigintConversion setting is set to true.

…bigintConversion config parameter to the connection, provide tests for both
)));
$response->setJsonBigintConversion(true);

$this->assertTrue(is_array($response->getData()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would also pass without the setJonBigintVersion(true), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this test would also pass without L215, but L215 makes the difference :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the test. But I assume this test would also have passed without the code changes you made? It is more for me to understand if we test if the bug was actually fixed or if we test that we can use the function without any side affects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it wouldn't since the return value of https://github.com/ruflin/Elastica/pull/1005/files#diff-b364251d02e70310f3c6e443372397d3L208 would be \stdClass and not an array and there is not conversion or casting happening till the end of method.

@ruflin
Copy link
Owner

ruflin commented Dec 9, 2015

@theDisco Thanks. Can you also update the CHANGELOG.md?

@theDisco
Copy link
Contributor Author

theDisco commented Dec 9, 2015

@ruflin Sure, done.

@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file based on the

### Bugfixes
- Function score query: corrected the `score_method` `average` to `avg` #975
- Set `json_decode()` assoc parameter to true in `Elastica\Response` #1005
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to bring this up again. But isn't the affect here, that if BIG_INT is enabled or not could be that the response object looks different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIG_INT_* setting converts integers bigger than PHP_INT_MAX to a string, so yes, the response will be different (well some data types will be different), but it is the only way to deal with this without overflowing the integer.

ruflin added a commit that referenced this pull request Dec 10, 2015
@ruflin ruflin merged commit 46fcb8c into ruflin:master Dec 10, 2015
@ruflin
Copy link
Owner

ruflin commented Dec 10, 2015

@theDisco Thanks for the contribution. We should definitively discuss if we should use JSON::parse($response, true) for the non JSON_BIG_INT conversion case. But I'm not sure if that will have any other side affects.

@theDisco
Copy link
Contributor Author

@ruflin if you look at the implementation of JSON::parse() you actually do not have to pass true as a second parameter:

        // extract arguments
        $args = func_get_args();
        // default to decoding into an assoc array
        if (sizeof($args) === 1) {
            $args[] = true;
        }
        // run decode
        $array = call_user_func_array('json_decode', $args);

And no, passing true would not have any side effects.

@ruflin
Copy link
Owner

ruflin commented Dec 10, 2015

@theDisco Ugh :-( Surprising that nobody of us spotted that in the past. But that is great news.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants