Bug #67167 [Asn]: Wrong return value from FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE

From: Date: Thu, 08 May 2014 05:06:30 +0000
Subject: Bug #67167 [Asn]: 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-185702@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 Updated by: levim@php.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: 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) Previous Comments: ------------------------------------------------------------------------ [2014-05-07 16:09:49] levim@php.net It appears that pajoye is correct; there is a convert_to_string call that messes all of this up. I'm not exactly sure what to do; it seems a rewrite is necessary to fix this behavior and that is beyond my current skill level. I could just bypass the convert_to_string call and special case this bug but that seems like a really bad idea. ------------------------------------------------------------------------ [2014-05-07 15:16:49] pajoye@php.net Keep in mind that the problem (if you pass booleans as well) is the string conversion happening before the filter is called. Making all Boolean checks impossible. ------------------------------------------------------------------------ [2014-05-05 07:07:32] peter dot schultz at classmarkets dot com Yes, passing null as the first argument seems to be broken too. Please note that there is a difference between passing null and an object though: http://3v4l.org/oFCpE Passing an object never worked correctly. ------------------------------------------------------------------------ [2014-05-04 02:07:12] infinitythe7th at gmx dot net This bug seems to exists since version 5.4.8 as discussed here: http://stackoverflow.com/questions/21469275/php-5-4-filter-var-filter-validate-boolean-bug-or-change-from-5-3 and being testable here: http://3v4l.org/PB6sp ------------------------------------------------------------------------ [2014-05-01 11:40:50] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67167&edit=1

« previous php.bugs (#185702) next »