Skip to content

Commit afa1045

Browse files
committed
Added explanatory comments to filter_input and filter_input_array to document
why some code that looks intuitively wrong is actually correct. Related to bug #51344 (FILTER_NULL_ON_FAILURE flag automatically set in filter_input() functions).
1 parent 129019b commit afa1045

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/filter/filter.c

+12
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ PHP_FUNCTION(filter_input)
780780
return;
781781
}
782782
}
783+
784+
/* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of
785+
* the function: normally when validation fails false is returned, and
786+
* when the input value doesn't exist NULL is returned. With the flag
787+
* set, NULL and false should be returned, respectively. Ergo, although
788+
* the code below looks incorrect, it's actually right. */
783789
if (filter_flags & FILTER_NULL_ON_FAILURE) {
784790
RETURN_FALSE;
785791
} else {
@@ -846,6 +852,12 @@ PHP_FUNCTION(filter_input_array)
846852
PHP_FILTER_GET_LONG_OPT(option, filter_flags);
847853
}
848854
}
855+
856+
/* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of
857+
* the function: normally when validation fails false is returned, and
858+
* when the input value doesn't exist NULL is returned. With the flag
859+
* set, NULL and false should be returned, respectively. Ergo, although
860+
* the code below looks incorrect, it's actually right. */
849861
if (filter_flags & FILTER_NULL_ON_FAILURE) {
850862
RETURN_FALSE;
851863
} else {

0 commit comments

Comments
 (0)