@@ -862,8 +862,8 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
862
862
tmp_ht = HASH_OF (obj_data );
863
863
#endif
864
864
865
- if (tmp_ht ) {
866
- ZEND_HASH_APPLY_COUNT (tmp_ht )++ ;
865
+ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION ( tmp_ht ) ) {
866
+ ZEND_HASH_INC_APPLY_COUNT (tmp_ht );
867
867
}
868
868
869
869
/* Persistable objects must always be serialized as BSON documents;
@@ -897,8 +897,8 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
897
897
bson_append_array_end (bson , & child );
898
898
}
899
899
900
- if (tmp_ht ) {
901
- ZEND_HASH_APPLY_COUNT (tmp_ht )-- ;
900
+ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION ( tmp_ht ) ) {
901
+ ZEND_HASH_DEC_APPLY_COUNT (tmp_ht );
902
902
}
903
903
zval_ptr_dtor (& obj_data );
904
904
return ;
@@ -970,12 +970,22 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
970
970
phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC , "Unexpected %s instance: %s" , php_phongo_type_ce -> name , Z_OBJCE_P (object )-> name );
971
971
#endif
972
972
return ;
973
- }
973
+ } else {
974
+ HashTable * tmp_ht = HASH_OF (object );
975
+
976
+ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION (tmp_ht )) {
977
+ ZEND_HASH_INC_APPLY_COUNT (tmp_ht );
978
+ }
974
979
975
- mongoc_log (MONGOC_LOG_LEVEL_TRACE , MONGOC_LOG_DOMAIN , "encoding document" );
976
- bson_append_document_begin (bson , key , key_len , & child );
977
- phongo_zval_to_bson (object , flags , & child , NULL TSRMLS_CC );
978
- bson_append_document_end (bson , & child );
980
+ mongoc_log (MONGOC_LOG_LEVEL_TRACE , MONGOC_LOG_DOMAIN , "encoding document" );
981
+ bson_append_document_begin (bson , key , key_len , & child );
982
+ phongo_zval_to_bson (object , flags , & child , NULL TSRMLS_CC );
983
+ bson_append_document_end (bson , & child );
984
+
985
+ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION (tmp_ht )) {
986
+ ZEND_HASH_DEC_APPLY_COUNT (tmp_ht );
987
+ }
988
+ }
979
989
}
980
990
981
991
static void phongo_bson_append (bson_t * bson , php_phongo_bson_flags_t flags , const char * key , long key_len , zval * entry TSRMLS_DC )
@@ -1023,16 +1033,16 @@ static void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, cons
1023
1033
bson_t child ;
1024
1034
HashTable * tmp_ht = HASH_OF (entry );
1025
1035
1026
- if (tmp_ht ) {
1027
- ZEND_HASH_APPLY_COUNT (tmp_ht )++ ;
1036
+ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION ( tmp_ht ) ) {
1037
+ ZEND_HASH_INC_APPLY_COUNT (tmp_ht );
1028
1038
}
1029
1039
1030
1040
bson_append_array_begin (bson , key , key_len , & child );
1031
1041
phongo_zval_to_bson (entry , flags , & child , NULL TSRMLS_CC );
1032
1042
bson_append_array_end (bson , & child );
1033
1043
1034
- if (tmp_ht ) {
1035
- ZEND_HASH_APPLY_COUNT (tmp_ht )-- ;
1044
+ if (tmp_ht && ZEND_HASH_APPLY_PROTECTION ( tmp_ht ) ) {
1045
+ ZEND_HASH_DEC_APPLY_COUNT (tmp_ht );
1036
1046
}
1037
1047
break ;
1038
1048
}
@@ -1191,7 +1201,7 @@ PHONGO_API void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, b
1191
1201
return ;
1192
1202
}
1193
1203
1194
- if (!ht_data || ZEND_HASH_APPLY_COUNT (ht_data ) > 1 ) {
1204
+ if (!ht_data || ZEND_HASH_GET_APPLY_COUNT (ht_data ) > 1 ) {
1195
1205
#if PHP_VERSION_ID >= 70000
1196
1206
if (Z_TYPE_P (data ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (data ), php_phongo_serializable_ce TSRMLS_CC )) {
1197
1207
#endif
0 commit comments