-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Add support for non-scalar foreach keys #278
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
Conversation
This patch basically changes the signature for
to
and does the necessary changes in all extensions (hopefully I didn't miss any ^^). The Things still to do: Figure out what to do with non-string/int keys when converting to array (iterator_to_array / CacheIterator). |
This commit adds a new ZEND_API function array_set_zval_key, that sets the key in the zval with the same semantics and errors as PHP would normally do. This new function is used to implement iterator_to_array and CachingIterator for non-scalar keys. In particular iterator_to_array() should now behave exactly the same as doing a manual loop with array insertion: foreach ($it as $k => $v) { $array[$k] = $v; }
Awesome work! 👍 |
good 发自我的小米手机 datibbaw notifications@github.com编写:
|
Which tests can/should I run to test the patch? |
@weltling Zend/tests and ext/spl/tests should cover the main thing. Though this change is mostly changing the use of the API in extensions all over the place, so "all of them" might be better :) |
@nikic Ok, thought that :) I was just wondering there are no tests for the special case mentioned in the RFC. Performed them altogether now, looks good. |
@@ -1171,6 +1171,27 @@ ZEND_API int zend_hash_get_current_key_ex(const HashTable *ht, char **str_index, | |||
return HASH_KEY_NON_EXISTANT; | |||
} | |||
|
|||
ZEND_API zval *zend_hash_get_current_key_zval_ex(const HashTable *ht, HashPosition *pos) { |
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.
currently, zend_hash.c didn't depend on zval struct, will it better move the function to zend_API ?
Merged in fcc6611. |
This is just a preliminary patch for the https://wiki.php.net/rfc/foreach-non-scalar-keys RFC.