From: Adam Harvey Date: Tue, 20 Apr 2010 04:31:11 +0000 (+0000) Subject: Added explanatory comments to filter_input and filter_input_array to document X-Git-Tag: php-5.3.3RC1~300 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b47136d332d6e133d7d5e30594488893b65d8534;p=php 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). --- diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 2ffe70499b..d6f2090b3a 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -780,6 +780,12 @@ PHP_FUNCTION(filter_input) return; } } + + /* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of + * the function: normally when validation fails false is returned, and + * when the input value doesn't exist NULL is returned. With the flag + * set, NULL and false should be returned, respectively. Ergo, although + * the code below looks incorrect, it's actually right. */ if (filter_flags & FILTER_NULL_ON_FAILURE) { RETURN_FALSE; } else { @@ -846,6 +852,12 @@ PHP_FUNCTION(filter_input_array) PHP_FILTER_GET_LONG_OPT(option, filter_flags); } } + + /* The FILTER_NULL_ON_FAILURE flag inverts the usual return values of + * the function: normally when validation fails false is returned, and + * when the input value doesn't exist NULL is returned. With the flag + * set, NULL and false should be returned, respectively. Ergo, although + * the code below looks incorrect, it's actually right. */ if (filter_flags & FILTER_NULL_ON_FAILURE) { RETURN_FALSE; } else {