@@ -774,12 +774,28 @@ void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char
774774 }
775775}
776776
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+
777789PHONGO_API void zval_to_bson (zval * data , php_phongo_bson_flags_t flags , bson_t * bson , bson_t * * bson_out TSRMLS_DC ) /* {{{ */
778790{
779791 HashPosition pos ;
780792 HashTable * ht_data = NULL ;
781793 zval * obj_data = NULL ;
782794
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+
783799 switch (Z_TYPE_P (data )) {
784800 case IS_OBJECT :
785801 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 *
813829
814830 break ;
815831 }
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 ;
817836
818837 case IS_ARRAY :
819838 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 *
850869 }
851870
852871 if (hash_type == HASH_KEY_IS_STRING ) {
853- if (Z_TYPE_P ( data ) == IS_OBJECT ) {
872+ if (ht_data_from_properties ) {
854873 const char * class_name ;
855874
856875 zend_unmangle_property_name (key , key_len - 1 , & class_name , (const char * * )& key );
857876 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+ }
858882 } else {
859883 /* Chop off the \0 from string lengths */
860884 key_len -= 1 ;
0 commit comments