@@ -1068,45 +1068,56 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
1068
1068
return ;
1069
1069
}
1070
1070
1071
+ #if PHP_VERSION_ID >= 70000
1072
+ {
1073
+ zend_string * key ;
1074
+ zval * value ;
1075
+
1076
+ ZEND_HASH_FOREACH_STR_KEY_VAL (ht_data , key , value ) {
1077
+ if (key ) {
1078
+ if (Z_TYPE_P (data ) == IS_OBJECT ) {
1079
+ const char * skey ;
1080
+ unsigned int skey_len = 0 ;
1081
+ const char * class_name ;
1082
+ zend_unmangle_property_name (key , & class_name , & skey );
1083
+
1084
+ if (flags & PHONGO_BSON_ADD_ID ) {
1085
+ if (!strncmp (skey , "_id" , sizeof ("_id" )- 1 )) {
1086
+ flags &= ~PHONGO_BSON_ADD_ID ;
1087
+ }
1088
+ }
1089
+ phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , skey , skey_len , Z_TYPE_P (value ), value TSRMLS_CC );
1090
+ } else {
1091
+ /* Chop off the \0 from string lengths */
1092
+ phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , key -> val , key -> len - 1 , Z_TYPE_P (value ), value TSRMLS_CC );
1093
+ }
1094
+ }
1095
+ } ZEND_HASH_FOREACH_END ();
1096
+ }
1097
+ #else
1071
1098
zend_hash_internal_pointer_reset_ex (ht_data , & pos );
1072
1099
for (;; zend_hash_move_forward_ex (ht_data , & pos )) {
1073
1100
unsigned int key_len = 0 ;
1074
1101
uint64_t index = 0 ;
1075
1102
char numbuf [32 ];
1076
1103
char * key = NULL ;
1077
- #if PHP_VERSION_ID >= 70000
1078
- zend_string * zs_key ;
1079
- zval * entry ;
1080
- #else
1081
1104
zval * * entry ;
1082
- #endif
1083
1105
int hash_type = HASH_KEY_NON_EXISTENT ;
1084
- #if PHP_VERSION_ID >= 70000
1085
- #else
1086
- hash_type = zend_hash_get_current_key_ex (ht_data , & zs_key , & index , 0 , & pos );
1087
- #endif
1106
+
1107
+ hash_type = zend_hash_get_current_key_ex (ht_data , & key , & key_len , & index , 0 , & pos );
1088
1108
1089
1109
if (hash_type == HASH_KEY_NON_EXISTENT ) {
1090
1110
break ;
1091
1111
}
1092
1112
1093
- #if PHP_VERSION_ID >= 70000
1094
- if ((entry = zend_hash_get_current_data_ex (ht_data , & pos )) != NULL ) {
1095
- #else
1096
1113
if (zend_hash_get_current_data_ex (ht_data , (void * * ) & entry , & pos ) == FAILURE ) {
1097
- #endif
1098
1114
break ;
1099
1115
}
1100
1116
1101
1117
if (hash_type == HASH_KEY_IS_STRING ) {
1102
1118
if (ht_data_from_properties ) {
1103
1119
const char * class_name ;
1104
- #if PHP_VERSION_ID >= 70000
1105
- zend_unmangle_property_name (zs_key , & class_name , (const char * * )& key );
1106
- zend_string_free (zs_key );
1107
- #else
1108
1120
zend_unmangle_property_name (key , key_len - 1 , & class_name , (const char * * )& key );
1109
- #endif
1110
1121
key_len = strlen (key );
1111
1122
1112
1123
/* Ignore non-public properties */
@@ -1126,12 +1137,9 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
1126
1137
} else {
1127
1138
key_len = bson_uint32_to_string (index , (const char * * )& key , numbuf , sizeof (numbuf ));
1128
1139
}
1129
- #if PHP_VERSION_ID >= 70000
1130
- phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , key , key_len , Z_TYPE_P (entry ), entry TSRMLS_CC );
1131
- #else
1132
1140
phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , key , key_len , Z_TYPE_PP (entry ), * entry TSRMLS_CC );
1133
- #endif
1134
1141
}
1142
+ #endif
1135
1143
1136
1144
if (flags & PHONGO_BSON_ADD_ID ) {
1137
1145
bson_oid_t oid ;
0 commit comments