Bug #67167 [Com]: Wrong return value from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE
| From: | infinitythe7th at gmx dot net | Date: | Thu, 08 May 2014 06:04:54 +0000 |
| Subject: | Bug #67167 [Com]: Wrong return value from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185707@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67167&edit=1
ID: 67167
Comment by: infinitythe7th at gmx dot net
Reported by: peter dot schultz at classmarkets dot com
Summary: Wrong return value from FILTER_VALIDATE_BOOLEAN,
FILTER_NULL_ON_FAILURE
Status: Assigned
Type: Bug
Package: Filter related
Operating System: Fedora 20
PHP Version: 5.5.12
Assigned To: levim
Block user comment: N
Private report: N
New Comment:
Not 100% sure about it, but that sounds as close to the documentation we have as I can see.
Previous Comments:
------------------------------------------------------------------------
[2014-05-08 05:56:20] levim@php.net
I think FILTER_VALIDATE_BOOLEAN with FILTER_NULL_ON_FAILURE should return null for an array, an
object that doesn't have __toString(), null, and a resource. For objects with __toString it
depends on the result of the cast; the same goes for floats and integers.
Sound good?
------------------------------------------------------------------------
[2014-05-08 05:22:33] levim@php.net
Here's the exact quote:
> 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.
It seems I misread; that does sound like it should return null for anything that fails
is_bool.
------------------------------------------------------------------------
[2014-05-08 05:18:27] infinitythe7th at gmx dot net
According to the Documentation here: http://www.php.net/manual/en/filter.filters.validate.php
The filter FILTER_VALIDATE_BOOLEAN with the flag FILTER_NULL_ON_FAILURE shall "[return] NULL
[...] for all non-boolean values".
In my opinion "null" is clearly a non-boolean value, so i can't really understand why
you would classify it returning false as being "by design".
------------------------------------------------------------------------
[2014-05-08 05:18:26] levim@php.net
I have a PR open for this issue; hopefully it will get resolved soon.
------------------------------------------------------------------------
[2014-05-08 05:06:28] levim@php.net
I have a fix pending for when an object that does not have a __toString method is passed. Based on
existing code and bug reports, it seems that casting to a string is by-design; this means that
passing null to filter_var would get cast to '' (empty string) which results in filter_var
returning false, not NULL (see http://www.php.net/manual/en/filter.filters.validate.php)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=67167
--
Edit this bug report at https://bugs.php.net/bug.php?id=67167&edit=1