Home » Php » filter var – PHP 5.4 filter_var() FILTER_VALIDATE_BOOLEAN bug? Or change from 5.3?

filter var – PHP 5.4 filter_var() FILTER_VALIDATE_BOOLEAN bug? Or change from 5.3?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I think I found a bug in PHP 5.4.23, but I suppose it is possible expected behavior as well. I am expecting a filter_var call to return null, but it isn’t. Is this code correct, and is my assumption that this is a bug and not a recent change correct as well?

Test code

var_dump(filter_var(null, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE));

PHP 5.3.28 Results:

NULL

PHP 5.4.23 Results:

bool(false)
How to&Answers:

Usually when a function returns NULL it succeded. false is returned when it failed (by convention).