Skip to content

Commit b169725

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix filter_var with callback and explicit REQUIRE_SCALAR
2 parents 99cd81c + 85ceb91 commit b169725

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP NEWS
2121
. Fixed bug GH-12123 (Compile error on MacOS with C++ extension when using
2222
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX). (kocsismate)
2323

24+
- Filter:
25+
. Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov)
26+
2427
- FPM:
2528
. Fixed GH-12077 (PHP 8.3.0RC1 borked socket-close-on-exec.phpt).
2629
(Jakub Zelenka)

ext/filter/filter.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,6 @@ static void php_filter_call(
484484
filter = zval_get_long(option);
485485
}
486486

487-
if ((option = zend_hash_str_find(filter_args_ht, "flags", sizeof("flags") - 1)) != NULL) {
488-
filter_flags = zval_get_long(option);
489-
490-
if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) {
491-
filter_flags |= FILTER_REQUIRE_SCALAR;
492-
}
493-
}
494-
495487
if ((option = zend_hash_str_find_deref(filter_args_ht, "options", sizeof("options") - 1)) != NULL) {
496488
if (filter != FILTER_CALLBACK) {
497489
if (Z_TYPE_P(option) == IS_ARRAY) {
@@ -502,6 +494,14 @@ static void php_filter_call(
502494
filter_flags = 0;
503495
}
504496
}
497+
498+
if ((option = zend_hash_str_find(filter_args_ht, "flags", sizeof("flags") - 1)) != NULL) {
499+
filter_flags = zval_get_long(option);
500+
501+
if (!(filter_flags & FILTER_REQUIRE_ARRAY || filter_flags & FILTER_FORCE_ARRAY)) {
502+
filter_flags |= FILTER_REQUIRE_SCALAR;
503+
}
504+
}
505505
}
506506

507507
if (Z_TYPE_P(filtered) == IS_ARRAY) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
FILTER_CALLBACK with explicit FILTER_REQUIRE_SCALAR
3+
--EXTENSIONS--
4+
filter
5+
--FILE--
6+
<?php
7+
function test($var) {
8+
$callback = function ($var) {
9+
return $var;
10+
};
11+
return filter_var($var, FILTER_CALLBACK, ['options' => $callback, 'flags' => FILTER_REQUIRE_SCALAR]);
12+
}
13+
var_dump(test('test'));
14+
var_dump(test(['test']));
15+
?>
16+
--EXPECT--
17+
string(4) "test"
18+
bool(false)

0 commit comments

Comments
 (0)