Skip to content

Commit 6b24741

Browse files
committed
We only allow object/array here, not need for this extra code
1 parent 28ae4f9 commit 6b24741

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/bson.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ int bson_to_zval(const unsigned char *data, int data_len, zval *retval)
845845
return 1;
846846
}
847847

848-
/* {{{ proto string BSON\fromArray(mixed data)
848+
/* {{{ proto string BSON\fromArray(array|object data)
849849
Returns the BSON representation of a value */
850850
PHP_FUNCTION(fromArray)
851851
{
@@ -854,23 +854,12 @@ PHP_FUNCTION(fromArray)
854854

855855
(void)return_value_ptr; (void)this_ptr; (void)return_value_used; /* We don't use these */
856856

857-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &data) == FAILURE) {
857+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "A", &data) == FAILURE) {
858858
return;
859859
}
860860

861861
bson = bson_new();
862-
863-
switch(Z_TYPE_P(data)) {
864-
case IS_OBJECT:
865-
case IS_ARRAY:
866-
zval_to_bson(data, PHONGO_BSON_NONE, bson, NULL TSRMLS_CC);
867-
break;
868-
869-
default:
870-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot convert scalar value '%s' to BSON", zend_zval_type_name(data));
871-
RETURN_NULL();
872-
break;
873-
}
862+
zval_to_bson(data, PHONGO_BSON_NONE, bson, NULL TSRMLS_CC);
874863

875864
RETVAL_STRINGL((const char *) bson_get_data(bson), bson->len, 1);
876865
bson_destroy(bson);

0 commit comments

Comments
 (0)