-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-2457: Fix using array items by reference #1697
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
PHPC-2457: Fix using array items by reference #1697
Conversation
ebe1657
to
caf057e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested test file rename and a code formatting complaint, but content LGTM.
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)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is clang-format
, but I find this formatting very bizarre.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
["x"]=> | ||
int(1) | ||
} | ||
object(stdClass)#4 (1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
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*_deref
php_array_fetch*_<type>
to always use*_deref
versionAfter 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_value
which 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_fetch
tophp_array_fetchc
when 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.