@@ -607,34 +607,43 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
607
607
608
608
if (instanceof_function (Z_OBJCE_P (object ), php_phongo_type_ce TSRMLS_CC )) {
609
609
if (instanceof_function (Z_OBJCE_P (object ), php_phongo_serializable_ce TSRMLS_CC )) {
610
- zval * retval = NULL ;
610
+ zval * obj_data = NULL ;
611
+ bson_t child ;
612
+ HashTable * tmp_ht ;
611
613
612
- zend_call_method_with_0_params (& object , NULL , NULL , BSON_SERIALIZE_FUNC_NAME , & retval );
613
- if (retval ) {
614
- bson_t child ;
615
- HashTable * tmp_ht ;
614
+ zend_call_method_with_0_params (& object , NULL , NULL , BSON_SERIALIZE_FUNC_NAME , & obj_data );
616
615
617
- convert_to_array_ex (& retval );
618
- tmp_ht = HASH_OF (retval );
616
+ if (!obj_data ) {
617
+ /* zend_call_method() failed */
618
+ return ;
619
+ }
619
620
620
- if (tmp_ht ) {
621
- tmp_ht -> nApplyCount ++ ;
622
- }
621
+ if (Z_TYPE_P ( obj_data ) != IS_ARRAY ) {
622
+ phongo_throw_exception ( PHONGO_ERROR_RUNTIME TSRMLS_CC , "Expected %s() to return an array, %s given" , BSON_SERIALIZE_FUNC_NAME , zend_get_type_by_const ( Z_TYPE_P ( obj_data ))) ;
623
+ zval_ptr_dtor ( & obj_data );
623
624
624
- bson_append_document_begin (bson , key , key_len , & child );
625
- if (instanceof_function (Z_OBJCE_P (object ), php_phongo_persistable_ce TSRMLS_CC )) {
626
- if (flags & PHONGO_BSON_ADD_CHILD_ODS ) {
627
- bson_append_binary (& child , PHONGO_ODM_FIELD_NAME , -1 , 0x80 , (const uint8_t * )Z_OBJCE_P (object )-> name , strlen (Z_OBJCE_P (object )-> name ));
628
- }
629
- }
630
- zval_to_bson (retval , flags , & child , NULL TSRMLS_CC );
631
- bson_append_document_end (bson , & child );
625
+ return ;
626
+ }
632
627
633
- if (tmp_ht ) {
634
- tmp_ht -> nApplyCount -- ;
628
+ tmp_ht = HASH_OF (obj_data );
629
+
630
+ if (tmp_ht ) {
631
+ tmp_ht -> nApplyCount ++ ;
632
+ }
633
+
634
+ bson_append_document_begin (bson , key , key_len , & child );
635
+ if (instanceof_function (Z_OBJCE_P (object ), php_phongo_persistable_ce TSRMLS_CC )) {
636
+ if (flags & PHONGO_BSON_ADD_CHILD_ODS ) {
637
+ bson_append_binary (& child , PHONGO_ODM_FIELD_NAME , -1 , 0x80 , (const uint8_t * )Z_OBJCE_P (object )-> name , strlen (Z_OBJCE_P (object )-> name ));
635
638
}
636
- zval_ptr_dtor (& retval );
637
639
}
640
+ zval_to_bson (obj_data , flags , & child , NULL TSRMLS_CC );
641
+ bson_append_document_end (bson , & child );
642
+
643
+ if (tmp_ht ) {
644
+ tmp_ht -> nApplyCount -- ;
645
+ }
646
+ zval_ptr_dtor (& obj_data );
638
647
return ;
639
648
}
640
649
0 commit comments