Skip to content

Commit

Permalink
Merge branch 'PHP-8.2' into PHP-8.3
Browse files Browse the repository at this point in the history
* PHP-8.2:
  Fix filter_var with callback and explicit REQUIRE_SCALAR
  • Loading branch information
iluuu1994 committed Sep 14, 2023
2 parents 99cd81c + 85ceb91 commit b169725
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ PHP NEWS
. Fixed bug GH-12123 (Compile error on MacOS with C++ extension when using
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX). (kocsismate)

- Filter:
. Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov)

- FPM:
. Fixed GH-12077 (PHP 8.3.0RC1 borked socket-close-on-exec.phpt).
(Jakub Zelenka)
Expand Down
16 changes: 8 additions & 8 deletions ext/filter/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,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) {
Expand All @@ -502,6 +494,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) {
Expand Down
18 changes: 18 additions & 0 deletions ext/filter/tests/filter_callback_require_scalar.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
FILTER_CALLBACK with explicit FILTER_REQUIRE_SCALAR
--EXTENSIONS--
filter
--FILE--
<?php
function test($var) {
$callback = function ($var) {
return $var;
};
return filter_var($var, FILTER_CALLBACK, ['options' => $callback, 'flags' => FILTER_REQUIRE_SCALAR]);
}
var_dump(test('test'));
var_dump(test(['test']));
?>
--EXPECT--
string(4) "test"
bool(false)

0 comments on commit b169725

Please sign in to comment.