Doc #41305 [Com]: BOOLEAN acts strange

From: Date: Sun, 21 Mar 2010 17:05:03 +0000
Subject: Doc #41305 [Com]: BOOLEAN acts strange
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-4083@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=41305&edit=1 ID: 41305 Comment by: pravila at alumni dot calpoly dot edu Reported by: Se dot Krebs at web dot de Summary: BOOLEAN acts strange Status: Closed Type: Documentation Problem Package: Documentation problem Operating System: Win32 PHP Version: 5.2.2 New Comment: 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()). <?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) ?> Previous Comments: ------------------------------------------------------------------------ [2007-06-17 11:56:07] gwynne@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. ------------------------------------------------------------------------ [2007-05-07 20:53:19] tony2001@php.net Both Ilia & Derick said it's a docu problem. Reclassified. ------------------------------------------------------------------------ [2007-05-06 18:13:56] Se dot Krebs at web dot de Description: ------------ FILTER_VALIDATE_BOOLEAN never returns null like its mentioned in the Manual ("otherwise null") without the FILTER_NULL_ON_FAILURE-Option. Even in the Manual is mentioned, that only String-"Booleans" will filterd, but true also returns true. Maybe without the Option the Manual is a kind of out-of-date, but the fact, that "false" is a Failure, but "true" isnt, seems strange to me. Reproduce code: --------------- var_dump( filter_var('false', FILTER_VALIDATE_BOOLEAN)); var_dump( filter_var(false, FILTER_VALIDATE_BOOLEAN)); var_dump( filter_var('true', FILTER_VALIDATE_BOOLEAN)); var_dump( filter_var(true, FILTER_VALIDATE_BOOLEAN)); var_dump( filter_var('false', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // bool(false) var_dump( filter_var(false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // NULL var_dump( filter_var('true', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // bool(false) var_dump( filter_var(true, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // bool(false) Expected result: ---------------- // first 4 lines: bool (false) NULL bool (true) NULL // last 4 lines the same Actual result: -------------- bool (false) bool (false) bool (true) bool (true) bool (false) NULL bool (true) bool (true) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=41305&edit=1

« previous php.doc.bugs (#4083) next »