PHPC-2457: Fix using array items by reference#1697
Merged
alcaeus merged 7 commits intomongodb:v1.20from Sep 27, 2024
Merged
Conversation
ebe1657 to
caf057e
Compare
jmikola
approved these changes
Sep 26, 2024
| static inline | ||
| zval *php_array_fetchl_deref(zval *zarr, const char *key, int key_len) { | ||
| return zval_deref_safe(php_array_fetchl(zarr, key, key_len)); | ||
| } |
Contributor
There was a problem hiding this comment.
I assume this is clang-format, but I find this formatting very bizarre.
Member
Author
There was a problem hiding this comment.
It's copy-paste from a previous occurrence, but I'll fix it
tests/query/bug2457-002.phpt
Outdated
| @@ -0,0 +1,49 @@ | |||
| --TEST-- | |||
| PHPC-2457: Query options can be passed reference | |||
Contributor
There was a problem hiding this comment.
I'd suggest swapping the names on these two tests, so once modifiers is removed in 2.0 we can delete its test and just be left with a bug2457-001.phpt file.
Merged
jmikola
reviewed
Sep 27, 2024
| ["x"]=> | ||
| int(1) | ||
| } | ||
| object(stdClass)#4 (1) { |
Contributor
There was a problem hiding this comment.
In the future, note that you can use %d for the object identifiers here, since those don't need to be asserted (and could change if we did internal refactoring).
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHPC-2457
Previous fixes for this were made in #1683 and #1223, but both attempts resulted in missed cases. #1694 fixes this for query modifiers and options, but a number of other occurrences were affected, as evidenced by the changes in this PR.
To fix this on a wider scale, I made a few adjustments to
php_array_api.h, some of them unrelated:php_array_fetch*_derefphp_array_fetch*_<type>to always use*_derefversionAfter making this change, I audited all usages of
php_array_fetch*and updated them accordingly. If references were correctly handled (such as inphongo_zval_to_bson_valuewhich always callsZVAL_DEREF), the call was not changed. Most cases immediately checked types after callingphp_array_fetch, which was changed tophp_array_fetch_deref.In addition, I changed a number of usages of
php_array_fetchtophp_array_fetchcwhen a constant string was used.I also included the tests added in #1694, but did not add tests for each and every usage that was changed. Let me know if you think those tests are necessary.