xref: /ext-ds/src/php/handlers/php_pair_handlers.c (revision f4fee1ad)
1 #include "php_pair_handlers.h"
2 #include "php_common_handlers.h"
3 #include "../objects/php_pair.h"
4 
5 zend_object_handlers php_pair_handlers;
6 
php_ds_pair_unset_property(zend_object * obj,zend_string * offset,void ** cache_slot)7 static void php_ds_pair_unset_property
8 #if PHP_VERSION_ID >= 80000
9 (zend_object *obj, zend_string *offset, void **cache_slot) {
10     if (zend_string_equals_literal(offset, "key") || zend_string_equals_literal(offset, "value")) {
11         zend_update_property_null(obj->ce, obj, ZSTR_VAL(offset), ZSTR_LEN(offset));
12     }
13 #else
14 (zval *obj, zval *offset, void **cache_slot) {
15     if (EXPECTED(Z_TYPE_P(offset) == IS_STRING)) {
16         if (ZVAL_EQUALS_STRING(offset, "key") || ZVAL_EQUALS_STRING(offset, "value")) {
17             zend_update_property_null(Z_OBJCE_P(obj), obj, Z_STRVAL_P(offset), Z_STRLEN_P(offset));
18         }
19     }
20 #endif
21 }
22 
23 static int php_ds_pair_count_elements
24 #if PHP_VERSION_ID >= 80000
25 (zend_object *obj, zend_long *count) {
26 #else
27 (zval *obj, zend_long *count) {
28 #endif
29     *count = 2;
30     return SUCCESS;
31 }
32 
33 static zend_object *php_ds_pair_clone_object
34 #if PHP_VERSION_ID >= 80000
35 (zend_object *obj) {
36     return php_ds_pair_create_clone((php_ds_pair_t*)obj);
37 #else
38 (zval *obj) {
39     return php_ds_pair_create_clone(Z_DS_PAIR_P(obj));
40 #endif
41 }
42 
43 void php_ds_register_pair_handlers()
44 {
45     memcpy(&php_pair_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
46 
47     php_pair_handlers.offset = XtOffsetOf(php_ds_pair_t, std);
48 
49     php_pair_handlers.clone_obj               = php_ds_pair_clone_object;
50     php_pair_handlers.cast_object             = php_ds_default_cast_object;
51     php_pair_handlers.count_elements          = php_ds_pair_count_elements;
52     php_pair_handlers.unset_property          = php_ds_pair_unset_property;
53 }
54