@@ -862,8 +862,8 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
862862 tmp_ht = HASH_OF (obj_data );
863863#endif
864864
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 );
867867 }
868868
869869 /* 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
897897 bson_append_array_end (bson , & child );
898898 }
899899
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 );
902902 }
903903 zval_ptr_dtor (& obj_data );
904904 return ;
@@ -970,12 +970,22 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
970970 phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC , "Unexpected %s instance: %s" , php_phongo_type_ce -> name , Z_OBJCE_P (object )-> name );
971971#endif
972972 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+ }
974979
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+ }
979989}
980990
981991static 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
10231033 bson_t child ;
10241034 HashTable * tmp_ht = HASH_OF (entry );
10251035
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 );
10281038 }
10291039
10301040 bson_append_array_begin (bson , key , key_len , & child );
10311041 phongo_zval_to_bson (entry , flags , & child , NULL TSRMLS_CC );
10321042 bson_append_array_end (bson , & child );
10331043
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 );
10361046 }
10371047 break ;
10381048 }
@@ -1191,7 +1201,7 @@ PHONGO_API void phongo_zval_to_bson(zval *data, php_phongo_bson_flags_t flags, b
11911201 return ;
11921202 }
11931203
1194- if (!ht_data || ZEND_HASH_APPLY_COUNT (ht_data ) > 1 ) {
1204+ if (!ht_data || ZEND_HASH_GET_APPLY_COUNT (ht_data ) > 1 ) {
11951205#if PHP_VERSION_ID >= 70000
11961206 if (Z_TYPE_P (data ) == IS_OBJECT && instanceof_function (Z_OBJCE_P (data ), php_phongo_serializable_ce TSRMLS_CC )) {
11971207#endif
0 commit comments