diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 836ee8345aff..edde05dcc993 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -551,14 +551,6 @@ static void php_filter_call( filter = zval_get_long(option); } - if ((option = zend_hash_str_find(filter_args_ht, "flags", sizeof("flags") - 1)) != NULL) { - filter_flags = zval_get_long(option); - - if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) { - filter_flags |= FILTER_REQUIRE_SCALAR; - } - } - if ((option = zend_hash_str_find_deref(filter_args_ht, "options", sizeof("options") - 1)) != NULL) { if (filter != FILTER_CALLBACK) { if (Z_TYPE_P(option) == IS_ARRAY) { @@ -569,6 +561,14 @@ static void php_filter_call( filter_flags = 0; } } + + if ((option = zend_hash_str_find(filter_args_ht, "flags", sizeof("flags") - 1)) != NULL) { + filter_flags = zval_get_long(option); + + if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) { + filter_flags |= FILTER_REQUIRE_SCALAR; + } + } } if (Z_TYPE_P(filtered) == IS_ARRAY) { diff --git a/ext/filter/tests/filter_callback_require_scalar.phpt b/ext/filter/tests/filter_callback_require_scalar.phpt new file mode 100644 index 000000000000..7259d1823d88 --- /dev/null +++ b/ext/filter/tests/filter_callback_require_scalar.phpt @@ -0,0 +1,18 @@ +--TEST-- +FILTER_CALLBACK with explicit FILTER_REQUIRE_SCALAR +--EXTENSIONS-- +filter +--FILE-- + $callback, 'flags' => FILTER_REQUIRE_SCALAR]); +} +var_dump(test('test')); +var_dump(test(['test'])); +?> +--EXPECT-- +string(4) "test" +bool(false)