rfc:object_keys_in_arrays
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:object_keys_in_arrays [2021/01/07 16:36] – created nikic | rfc:object_keys_in_arrays [2021/01/08 15:07] – nikic | ||
---|---|---|---|
Line 33: | Line 33: | ||
The enumerations RFC suggests to instead use either '' | The enumerations RFC suggests to instead use either '' | ||
- | This RFC proposes to address this issue by allowing the use of object keys (and thus enum keys) inside array. | + | This RFC proposes to address this issue by allowing the use of object keys (and thus enum keys) inside array. This change will also make it simpler to support other key kinds in the future, for example if PHP were to switch to arbitrary-precision integers. |
===== Proposal ===== | ===== Proposal ===== | ||
Line 53: | Line 53: | ||
Object keys are compared by object identity. That is, '' | Object keys are compared by object identity. That is, '' | ||
- | While an extension to support custom object hashing and comparison overloads may be possible in the future, it is very much out of scope of this proposal. | + | While an extension to support custom object hashing and comparison overloads may be possible in the future, it is very much out of scope of this proposal. '' |
+ | |||
+ | ==== Impact on standard library functions ==== | ||
+ | |||
+ | For most standard library functions the behavior of object keys is straightforward. E.g. '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 68: | Line 76: | ||
</ | </ | ||
- | It should be noted that Traversables could already yield non-string, non-integer keys beforehand and as such more generic code already needs to handle them gracefully. | + | It should be noted that Traversables could already yield non-string, non-integer keys beforehand and as such more generic code already needs to handle them gracefully. |
===== Implementation Impact ===== | ===== Implementation Impact ===== | ||
Line 93: | Line 101: | ||
The size of this structure remains the same on 64-bit systems (on legacy 32-bit systems it is 8 bytes larger). | The size of this structure remains the same on 64-bit systems (on legacy 32-bit systems it is 8 bytes larger). | ||
- | The stored hash value is reduced to 32-bits in order to fit into u2 space. As hash indexes | + | The stored hash value is reduced to 32-bits in order to fit into u2 space. As hash indices |
- | The key zval may have type '' | + | The key zval may have type '' |
- | In order to support object keys (and potentially other key types in the future), a new '' | + | In order to support object keys (and potentially other key types in the future), a new '' |
A non-exhaustive list of new functions: | A non-exhaustive list of new functions: | ||
Line 110: | Line 118: | ||
ZEND_API zval* ZEND_FASTCALL zend_hash_zkey_find(const HashTable *ht, zval *key); | ZEND_API zval* ZEND_FASTCALL zend_hash_zkey_find(const HashTable *ht, zval *key); | ||
static zend_always_inline zend_bool zend_hash_zkey_exists(const HashTable *ht, zval *key); | static zend_always_inline zend_bool zend_hash_zkey_exists(const HashTable *ht, zval *key); | ||
+ | static zend_always_inline zval *_zend_hash_zkey_append(HashTable *ht, zval *key, zval *zv); | ||
</ | </ | ||
+ | |||
+ | **TODO**: It's not clear yet how to handle the case where now u2 initialization is given. Should there be additional functions for that case, or a function to handle the initialization up-front? | ||
Similarly, '' | Similarly, '' | ||
Line 120: | Line 131: | ||
</ | </ | ||
- | The existing '' | + | The existing '' |
The '' | The '' | ||
Line 157: | Line 168: | ||
The new macros can be polyfilled for older PHP versions, which is also why this introduces new macros rather than modifying existing ones. | The new macros can be polyfilled for older PHP versions, which is also why this introduces new macros rather than modifying existing ones. | ||
+ | |||
+ | The '' | ||
+ | |||
+ | <code c> | ||
+ | /* This function populates `key` with a copy of the key, or a null zval if exhausted. */ | ||
+ | ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos); | ||
+ | |||
+ | /* This function returns the key zval directly, or NULL if exhausted. */ | ||
+ | ZEND_API zval* ZEND_FASTCALL zend_hash_get_current_zkey(const HashTable *ht, HashPosition *pos); | ||
+ | </ | ||
+ | |||
+ | The '' | ||
===== Vote ===== | ===== Vote ===== |
rfc/object_keys_in_arrays.txt · Last modified: 2021/01/11 14:22 by nikic