@@ -569,6 +569,33 @@ void object_to_bson(zval *object, const char *key, long key_len, bson_t *bson TS
569
569
}
570
570
571
571
if (instanceof_function (Z_OBJCE_P (object ), php_phongo_type_ce TSRMLS_CC )) {
572
+ if (instanceof_function (Z_OBJCE_P (object ), php_phongo_serializable_ce TSRMLS_CC )) {
573
+ zval * retval = NULL ;
574
+
575
+ zend_call_method_with_0_params (& object , NULL , NULL , BSON_SERIALIZE_FUNC_NAME , & retval );
576
+ if (retval ) {
577
+ bson_t child ;
578
+ HashTable * tmp_ht ;
579
+
580
+ convert_to_array_ex (& retval );
581
+ tmp_ht = HASH_OF (retval );
582
+
583
+ if (tmp_ht ) {
584
+ tmp_ht -> nApplyCount ++ ;
585
+ }
586
+
587
+ bson_append_array_begin (bson , key , key_len , & child );
588
+ zval_to_bson (retval , PHONGO_BSON_NONE , & child , NULL TSRMLS_CC );
589
+ bson_append_array_end (bson , & child );
590
+
591
+ if (tmp_ht ) {
592
+ tmp_ht -> nApplyCount -- ;
593
+ }
594
+ zval_ptr_dtor (& retval );
595
+ }
596
+ return ;
597
+ }
598
+
572
599
if (instanceof_function (Z_OBJCE_P (object ), php_phongo_objectid_ce TSRMLS_CC )) {
573
600
bson_oid_t oid ;
574
601
@@ -831,22 +858,26 @@ void php_phongo_bson_typemap_to_state(zval *typemap, php_phongo_bson_typemap *ma
831
858
zend_class_entry * array_ce = NULL , * document_ce = NULL ;
832
859
833
860
classname = php_array_fetchl_string (typemap , "array" , sizeof ("array" )- 1 , & classname_len , & classname_free );
834
- array_ce = zend_fetch_class (classname , classname_len , ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
861
+ if (classname_len ) {
862
+ array_ce = zend_fetch_class (classname , classname_len , ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
835
863
836
- if (instanceof_function (array_ce , php_phongo_unserializable_ce TSRMLS_CC )) {
837
- map -> array = array_ce ;
838
- }
839
- if (classname_free ) {
840
- efree (classname );
864
+ if (instanceof_function (array_ce , php_phongo_unserializable_ce TSRMLS_CC )) {
865
+ map -> array = array_ce ;
866
+ }
867
+ if (classname_free ) {
868
+ efree (classname );
869
+ }
841
870
}
842
871
843
872
classname = php_array_fetchl_string (typemap , "document" , sizeof ("document" )- 1 , & classname_len , & classname_free );
844
- document_ce = zend_fetch_class (classname , classname_len , ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
845
- if (instanceof_function (document_ce , php_phongo_unserializable_ce TSRMLS_CC )) {
846
- map -> document = document_ce ;
847
- }
848
- if (classname_free ) {
849
- efree (classname );
873
+ if (classname_len ) {
874
+ document_ce = zend_fetch_class (classname , classname_len , ZEND_FETCH_CLASS_AUTO TSRMLS_CC );
875
+ if (instanceof_function (document_ce , php_phongo_unserializable_ce TSRMLS_CC )) {
876
+ map -> document = document_ce ;
877
+ }
878
+ if (classname_free ) {
879
+ efree (classname );
880
+ }
850
881
}
851
882
}
852
883
}
0 commit comments