Wrong return value from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE
| Bug #67167 | Wrong return value from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Submitted: | 2014-05-01 11:40 UTC | Modified: | 2019-03-18 10:19 UTC |
|
||||||
| From: | peter dot schultz at classmarkets dot com | Assigned: | cmb (profile) | |||||||
| Status: | Closed | Package: | Filter related | |||||||
| PHP Version: | 5.5.12 | OS: | Fedora 20 | |||||||
| Private report: | No | CVE-ID: | None | |||||||
[2014-05-01 11:40 UTC] peter dot schultz at classmarkets dot com
Description: ------------ --- From manual page: http://www.php.net/filter.filters.validate --- FILTER_VALIDATE_BOOLEAN with the FILTER_NULL_ON_FAILURE flag return false if the first argument is an object. According to the documentation it should be null. Test script: --------------- <?php var_dump(filter_var(new \StdClass(), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));' Expected result: ---------------- NULL Actual result: -------------- bool(false)
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2014-05-05 07:07 UTC] peter dot schultz at classmarkets dot com
[2014-05-07 15:14 UTC] levim@php.net
-Status: Open +Status: Assigned -Package: *General Issues +Package: Filter related -Assigned To: +Assigned To: levim
[2014-05-07 15:16 UTC] pajoye@php.net
[2014-05-07 16:09 UTC] levim@php.net
[2014-05-08 05:06 UTC] levim@php.net
[2014-05-08 05:18 UTC] levim@php.net
[2014-05-08 05:18 UTC] infinitythe7th at gmx dot net
[2014-05-08 05:22 UTC] levim@php.net
[2014-05-08 05:56 UTC] levim@php.net
[2014-05-08 06:04 UTC] infinitythe7th at gmx dot net
[2014-05-08 07:32 UTC] pajoye@php.net
[2015-09-02 13:48 UTC] cmb@php.net
[2015-09-03 00:27 UTC] levim@php.net
-Status: Assigned +Status: Closed
[2015-09-03 00:29 UTC] levim@php.net
-Status: Closed +Status: Re-Opened
[2015-09-03 00:29 UTC] levim@php.net
[2015-09-03 18:10 UTC] ab@php.net
-Status: Re-Opened +Status: Closed
[2016-01-25 09:43 UTC] b-roeser at gmx dot net
Hi there, Has this bugfix actually landed? If so, in which version, can't find it in the changelog. I'm currently testing on PHP 5.6.11-1ubuntu3.1 and I can still reproduce the problem. Here is my test case: <?php class x {} class y { public $m = 'n'; function doStuff() { $this->m = 'l'; } } $value = 'x'; var_dump(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // expected: NULL – works as expected $value = new stdClass(); var_dump(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // expected: NULL – returns false $value = new x(); var_dump(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // expected: NULL – returns false $value = new y(); var_dump(filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)); // expected: NULL – returns false var_dump((string)$value); This is the output I get: NULL bool(false) bool(false) bool(false) PHP Catchable fatal error: Object of class y could not be converted to string in /home/benedict/Repositories/wellid/testcase.php on line 30 PHP Stack trace: PHP 1. {main}() /home/benedict/Repositories/wellid/testcase.php:0 benedict@minerva:~/Repositories/wellid$ vim testcase.php benedict@minerva:~/Repositories/wellid$ php -f testcase.php NULL bool(false) bool(false) bool(false) PHP Catchable fatal error: Object of class y could not be converted to string in /home/benedict/Repositories/wellid/testcase.php on line 30 PHP Stack trace: PHP 1. {main}() /home/benedict/Repositories/wellid/testcase.php:0 As you can see, none of these have a __toString()-method. Am I missing something?[2016-01-25 09:46 UTC] b-roeser at gmx dot net
[2016-09-09 10:26 UTC] cmb@php.net
-Status: Closed +Status: Re-Opened -Assigned To: levim +Assigned To: cmb
[2016-09-09 10:26 UTC] cmb@php.net
[2016-09-09 10:58 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed
[2019-03-18 09:59 UTC] lebadap at gmail dot com
[2019-03-18 10:19 UTC] cmb@php.net
> is false, when it should be null according to the docs No. The filter_var() docs[1] state: | Note that scalar values are converted to string internally | before they are filtered. So basically you're calling: filter_var('', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) However, FILTER_VALIDATE_BOOLEAN is documented[2] to: | If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for | "0", "false", "off", "no", and "" […] So the behavior complies to the documentation. [1] <http://php.net/manual/en/function.filter-var.php> [2] <http://de2.php.net/manual/en/filter.filters.validate.php>