Bug #68761 [Com]: filter_var(null) returns false with FILTER_NULL_ON_FAILURE

From: Date: Thu, 15 Jan 2015 10:53:52 +0000
Subject: Bug #68761 [Com]: filter_var(null) returns false with FILTER_NULL_ON_FAILURE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189968@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68761&edit=1 ID: 68761 Comment by: ppasindud at gmail dot com Reported by: tonyli dot lives at gmail dot com Summary: filter_var(null) returns false with FILTER_NULL_ON_FAILURE Status: Open Type: Bug Package: Filter related Operating System: Ubuntu 12.04 PHP Version: 5.5.20 Block user comment: N Private report: N New Comment: Works correctly in php-src master Previous Comments: ------------------------------------------------------------------------ [2015-01-06 22:17:55] tonyli dot lives at gmail dot com Description: ------------ Even with the flag on, trying to filter null returns false when it should be still null (as null is not a boolean). As per the documentation: If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for "0", "false", "off", "no", and "", and NULL is returned for all non-boolean values. Similar to: https://bugs.php.net/bug.php?id=67167 Test script: --------------- var_dump(filter_var(null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); var_dump(filter_var(false, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); var_dump(filter_var(true, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); var_dump(filter_var('test', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); Expected result: ---------------- bool(false) bool(false) bool(true) NULL Actual result: -------------- NULL bool(false) bool(true) NULL ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68761&edit=1

« previous php.bugs (#189968) next »