Bug #51344 [Opn->Asn]: FILTER_NULL_ON_FAILURE flag automatically set in filter_input() functions.

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at http://bugs.php.net/bug.php?id=51344&edit=1

 ID:               51344
 Updated by:       [email protected]
 Reported by:      pravila at alumni dot calpoly dot edu
 Summary:          FILTER_NULL_ON_FAILURE flag automatically set in
                   filter_input() functions.
-Status:           Open
+Status:           Assigned
 Type:             Bug
 Package:          Filter related
 Operating System: Linux
 PHP Version:      5.2.13
-Assigned To:      
+Assigned To:      aharvey



Previous Comments:
------------------------------------------------------------------------
[2010-04-11 01:15:01] mats dot lindh at gmail dot com

Patch to solve issue has been added. Patch is against current trunk but
can probably be applied cleanly against 5.2 and 5.3 too. Issue stems
from a simple error where RETURN_NULL(); and RETURN_FALSE; statements
seems to have gotten mixed up.

Test is also attached in patch, based on the example in the bug report.

------------------------------------------------------------------------
[2010-03-21 18:02:46] pravila at alumni dot calpoly dot edu

Description:
------------
* This is different than bug http://bugs.php.net/bug.php?id=41305 *

The filter_var() vs. the filter_input() behave differently when using
the 
FILTER_VALIDATE_BOOLEAN filter when the variable/input doesn't exist.

More specifically, it seems as if the FILTER_NULL_ON_FAILURE flag is set

automatically in the filter_input() function.

(Note: same behavior for filter_var_array() vs. filter_input_array()).

From PHPINFO():
filter.default = unsafe_raw
filter.default_flags = no value
Revision: 1.52.2.39.2.16

Test script:
---------------
<?php
// example.com/script.php?arg1=yes&arg3=no

// filtering by variable
$var1 = filter_var($_GET["arg1"], FILTER_VALIDATE_BOOLEAN);
$var2 = filter_var($_GET["arg2"], FILTER_VALIDATE_BOOLEAN);
$var3 = filter_var($_GET["arg3"], FILTER_VALIDATE_BOOLEAN);

// filtering by input
$input1 = filter_input(INPUT_GET, "arg1", FILTER_VALIDATE_BOOLEAN);
$input2 = filter_input(INPUT_GET, "arg2", FILTER_VALIDATE_BOOLEAN);
$input3 = filter_input(INPUT_GET, "arg3", FILTER_VALIDATE_BOOLEAN);

// as expected...
var_dump($var1);      // bool(true)
var_dump($var2);      // bool(false)
var_dump($var3);      // bool(false)

// NULL is not an expected return unless the FILTER_NULL_ON_FAILURE flag
is set...
var_dump($input1);    // bool(true)
var_dump($input2);    // NULL
var_dump($input3);    // bool(false)
?>

Expected result:
----------------
As per the documentation, we expect the output of the code above to be:

bool(true)
bool(false)
bool(false)
bool(true)
bool(false)
bool(false)

Actual result:
--------------
Even though the FILTER_NULL_ON_FAILURE flag is NOT set, we DO get a NULL
value in 
the output:

bool(true)
bool(false)
bool(false)
bool(true)
NULL
bool(false)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51344&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.