@@ -981,9 +981,13 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
981981 zval_to_bson (object , flags , & child , NULL TSRMLS_CC );
982982 bson_append_document_end (bson , & child );
983983}
984- void phongo_bson_append (bson_t * bson , php_phongo_bson_flags_t flags , const char * key , long key_len , int entry_type , zval * entry TSRMLS_DC )
984+
985+ static void phongo_bson_append (bson_t * bson , php_phongo_bson_flags_t flags , const char * key , long key_len , zval * entry TSRMLS_DC )
985986{
986- switch (entry_type )
987+ #if PHP_VERSION_ID >= 70000
988+ try_again :
989+ #endif
990+ switch (Z_TYPE_P (entry ))
987991 {
988992 case IS_NULL :
989993 bson_append_null (bson , key , key_len );
@@ -1043,12 +1047,16 @@ void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char
10431047
10441048#if PHP_VERSION_ID >= 70000
10451049 case IS_INDIRECT :
1046- phongo_bson_append (bson , flags , key , key_len , Z_TYPE_P ( Z_INDIRECT_P ( entry )), Z_INDIRECT_P (entry ) TSRMLS_DC );
1050+ phongo_bson_append (bson , flags , key , key_len , Z_INDIRECT_P (entry ) TSRMLS_DC );
10471051 break ;
1052+
1053+ case IS_REFERENCE :
1054+ ZVAL_DEREF (entry );
1055+ goto try_again ;
10481056#endif
10491057
10501058 default :
1051- phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC , "Got unsupported type %d '%s'" , entry_type , zend_get_type_by_const (entry_type ));
1059+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE TSRMLS_CC , "Got unsupported type %d '%s'" , Z_TYPE_P ( entry ) , zend_get_type_by_const (Z_TYPE_P ( entry ) ));
10521060 }
10531061}
10541062
@@ -1231,7 +1239,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
12311239 phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID ,
12321240 member ? ZSTR_VAL (member ) : ZSTR_VAL (key ),
12331241 member ? ZSTR_LEN (member ) : ZSTR_LEN (key ),
1234- Z_TYPE_P ( value ), value TSRMLS_CC );
1242+ value TSRMLS_CC );
12351243
12361244 if (member ) {
12371245 zend_string_release (member );
@@ -1242,14 +1250,14 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
12421250 flags &= ~PHONGO_BSON_ADD_ID ;
12431251 }
12441252 }
1245- phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , ZSTR_VAL (key ), ZSTR_LEN (key ), Z_TYPE_P ( value ), value TSRMLS_CC );
1253+ phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , ZSTR_VAL (key ), ZSTR_LEN (key ), value TSRMLS_CC );
12461254 }
12471255 } else {
12481256 char numbuf [32 ];
12491257 const char * skey ;
12501258 unsigned int skey_len = 0 ;
12511259 skey_len = bson_uint32_to_string (num_key , (const char * * )& skey , numbuf , sizeof (numbuf ));
1252- phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , skey , skey_len , Z_TYPE_P ( value ), value TSRMLS_CC );
1260+ phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , skey , skey_len , value TSRMLS_CC );
12531261 }
12541262 } ZEND_HASH_FOREACH_END ();
12551263 }
@@ -1296,7 +1304,7 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
12961304 } else {
12971305 key_len = bson_uint32_to_string (index , (const char * * )& key , numbuf , sizeof (numbuf ));
12981306 }
1299- phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , key , key_len , Z_TYPE_PP ( entry ), * entry TSRMLS_CC );
1307+ phongo_bson_append (bson , flags & ~PHONGO_BSON_ADD_ID , key , key_len , * entry TSRMLS_CC );
13001308 }
13011309#endif
13021310
0 commit comments