rfc:object_keys_in_arrays
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:object_keys_in_arrays [2021/01/08 11:23] – nikic | rfc:object_keys_in_arrays [2021/01/11 14:22] (current) – nikic | ||
---|---|---|---|
Line 4: | Line 4: | ||
* Status: Draft | * Status: Draft | ||
* Target Version: PHP 8.1 | * Target Version: PHP 8.1 | ||
- | * Implementation: | + | * Implementation: |
===== Introduction ===== | ===== Introduction ===== | ||
Line 60: | Line 60: | ||
* '' | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * ... | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 101: | Line 104: | ||
The stored hash value is reduced to 32-bits in order to fit into u2 space. As hash indices are already limited to 32-bits, this is not problematic. | The stored hash value is reduced to 32-bits in order to fit into u2 space. As hash indices are already limited to 32-bits, this is not problematic. | ||
- | The key zval may have type '' | + | The key zval may have type '' |
- | In order to support | + | A number of new hash APIs for working with object keys is added: |
- | A non-exhaustive list of new functions: | + | <code c> |
+ | ZEND_API zval* ZEND_FASTCALL zend_hash_obj_key_add(HashTable *ht, zend_object *obj_key, zval *val); | ||
+ | ZEND_API zval* ZEND_FASTCALL zend_hash_obj_key_add_new(HashTable *ht, zend_object *obj_key, zval *val); | ||
+ | ZEND_API zval* ZEND_FASTCALL zend_hash_obj_key_update(HashTable *ht, zend_object *obj_key, zval *val); | ||
+ | ZEND_API zend_result ZEND_FASTCALL zend_hash_obj_key_del(HashTable *ht, zend_object *obj_key); | ||
+ | ZEND_API zval* ZEND_FASTCALL zend_hash_obj_key_find(const HashTable *ht, zend_object *obj_key); | ||
+ | </ | ||
+ | |||
+ | However, the majority | ||
+ | |||
+ | Instead, a new '' | ||
+ | |||
+ | The following | ||
<code c> | <code c> | ||
- | // This omits various _ind, _ptr, etc variants. | ||
ZEND_API zval* ZEND_FASTCALL zend_hash_zkey_add_or_update(HashTable *ht, zval *key, zval *val, uint32_t flag); | ZEND_API zval* ZEND_FASTCALL zend_hash_zkey_add_or_update(HashTable *ht, zval *key, zval *val, uint32_t flag); | ||
ZEND_API zval* ZEND_FASTCALL zend_hash_zkey_update(HashTable *ht, zval *key, zval *val); | ZEND_API zval* ZEND_FASTCALL zend_hash_zkey_update(HashTable *ht, zval *key, zval *val); | ||
Line 116: | Line 130: | ||
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); | ||
+ | |||
+ | // This is a low-level API that requires the hash value in u2 to be initialized. | ||
static zend_always_inline zval *_zend_hash_zkey_append(HashTable *ht, zval *key, zval *zv); | 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 166: | Line 180: | ||
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.1610105006.txt.gz · Last modified: 2021/01/08 11:23 by nikic