Skip to content

Commit f2e9953

Browse files
jmikoladerickr
authored andcommitted
PHPC-393: Don't BSON-encode non-public properties in PHP 7
1 parent 9047b3d commit f2e9953

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/bson.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,13 @@ static bool is_public_property(zend_class_entry *ce, const char *prop_name, int
10471047
zend_property_info *property_info;
10481048
zval member;
10491049

1050+
#if PHP_VERSION_ID >= 70000
1051+
ZVAL_STRINGL(&member, prop_name, prop_name_len);
1052+
property_info = zend_get_property_info(ce, Z_STR(member), 1 TSRMLS_CC);
1053+
#else
10501054
ZVAL_STRINGL(&member, prop_name, prop_name_len, 0);
10511055
property_info = zend_get_property_info(ce, &member, 1 TSRMLS_CC);
1056+
#endif
10521057

10531058
return (property_info && (property_info->flags & ZEND_ACC_PUBLIC));
10541059
}
@@ -1170,6 +1175,11 @@ PHONGO_API void zval_to_bson(zval *data, php_phongo_bson_flags_t flags, bson_t *
11701175
const char *class_name;
11711176
zend_unmangle_property_name_ex(key, &class_name, &skey, &skey_len);
11721177

1178+
/* Ignore non-public properties */
1179+
if (!is_public_property(Z_OBJCE_P(data), skey, skey_len TSRMLS_CC)) {
1180+
continue;
1181+
}
1182+
11731183
if (flags & PHONGO_BSON_ADD_ID) {
11741184
if (!strncmp(skey, "_id", sizeof("_id")-1)) {
11751185
flags &= ~PHONGO_BSON_ADD_ID;

0 commit comments

Comments
 (0)