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

From: Date: Mon, 25 Jan 2016 09:46:18 +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-198876@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: b-roeser 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: Closed 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: Sorry, when pasting the output from the console, I pasted a little bit too much, hope it is still clear. Previous Comments: ------------------------------------------------------------------------ [2016-01-25 09:43:49] 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? ------------------------------------------------------------------------ [2015-09-03 18:10:16] ab@php.net Automatic comment on behalf of levim Revision: http://git.php.net/?p=php-src.git;a=commit;h=432dc527adcbc3bf4809f6315350300d42c16c52 Log: Partially fix bug #67167 - Wrong return value... ------------------------------------------------------------------------ [2015-09-03 00:29:16] levim@php.net I have applied a partial fix that works applies when you pass an object that doesn't have a __toString method. This will fix the specific code noted in test script, but won't fix some other cases (such as passing null) ------------------------------------------------------------------------ [2015-09-03 00:27:09] levim@php.net Automatic comment on behalf of levim Revision: http://git.php.net/?p=php-src.git;a=commit;h=432dc527adcbc3bf4809f6315350300d42c16c52 Log: Partially fix bug #67167 - Wrong return value... ------------------------------------------------------------------------ [2015-09-02 13:48:45] cmb@php.net > It appears that pajoye is correct; there is a convert_to_string > call that messes all of this up. I wonder why the first argument of filter_var() isn't string instead of mixed. ------------------------------------------------------------------------ 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

« previous php.bugs (#198876) next »