@@ -774,12 +774,28 @@ void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char
774
774
}
775
775
}
776
776
777
+ static bool is_public_property (zend_class_entry * ce , const char * prop_name , int prop_name_len TSRMLS_DC ) /* {{{ */
778
+ {
779
+ zend_property_info * property_info ;
780
+ zval member ;
781
+
782
+ ZVAL_STRINGL (& member , prop_name , prop_name_len , 0 );
783
+ property_info = zend_get_property_info (ce , & member , 1 TSRMLS_CC );
784
+
785
+ return (property_info && (property_info -> flags & ZEND_ACC_PUBLIC ));
786
+ }
787
+ /* }}} */
788
+
777
789
PHONGO_API void zval_to_bson (zval * data , php_phongo_bson_flags_t flags , bson_t * bson , bson_t * * bson_out TSRMLS_DC ) /* {{{ */
778
790
{
779
791
HashPosition pos ;
780
792
HashTable * ht_data = NULL ;
781
793
zval * obj_data = NULL ;
782
794
795
+ /* If we will be encoding a class that may contain protected and private
796
+ * properties, we'll need to filter them out later. */
797
+ bool ht_data_from_properties = false;
798
+
783
799
switch (Z_TYPE_P (data )) {
784
800
case IS_OBJECT :
785
801
if (instanceof_function (Z_OBJCE_P (data ), php_phongo_serializable_ce TSRMLS_CC )) {
@@ -813,7 +829,10 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
813
829
814
830
break ;
815
831
}
816
- /* break intentionally omitted */
832
+
833
+ ht_data = Z_OBJ_HT_P (data )-> get_properties (data TSRMLS_CC );
834
+ ht_data_from_properties = true;
835
+ break ;
817
836
818
837
case IS_ARRAY :
819
838
ht_data = HASH_OF (data );
@@ -850,11 +869,16 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
850
869
}
851
870
852
871
if (hash_type == HASH_KEY_IS_STRING ) {
853
- if (Z_TYPE_P ( data ) == IS_OBJECT ) {
872
+ if (ht_data_from_properties ) {
854
873
const char * class_name ;
855
874
856
875
zend_unmangle_property_name (key , key_len - 1 , & class_name , (const char * * )& key );
857
876
key_len = strlen (key );
877
+
878
+ /* Ignore non-public properties */
879
+ if (!is_public_property (Z_OBJCE_P (data ), key , key_len TSRMLS_CC )) {
880
+ continue ;
881
+ }
858
882
} else {
859
883
/* Chop off the \0 from string lengths */
860
884
key_len -= 1 ;
0 commit comments