Bug #68761 [NEW]: filter_var(null) returns false with FILTER_NULL_ON_FAILURE
| From: | tonyli dot lives at gmail dot com | Date: | Tue, 06 Jan 2015 22:17:56 +0000 |
| Subject: | Bug #68761 [NEW]: filter_var(null) returns false with FILTER_NULL_ON_FAILURE | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189693@lists.php.net to get a copy of this message | ||
From: tonyli dot lives at gmail dot com
Operating system: Ubuntu 12.04
PHP version: 5.5.20
Package: Filter related
Bug Type: Bug
Bug description:filter_var(null) returns false with FILTER_NULL_ON_FAILURE
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 bug report at https://bugs.php.net/bug.php?id=68761&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68761&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68761&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68761&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68761&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68761&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68761&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68761&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68761&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68761&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68761&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68761&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68761&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68761&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68761&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68761&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68761&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68761&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68761&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68761&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68761&r=mysqlcfg