PHP 5.4 filter_var() FILTER_VALIDATE_BOOLEAN bug? Or change from 5.3?
Asked Answered
V

1

8

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)
Viticulture answered 30/1, 2014 at 23:1 Comment(6)
Confirmed: 3v4l.org/PB6spSolenoid
@RocketHazmat That is a ridiculously awesome tool. Thanks for that link!Viticulture
It might be bug (or a fixed one): bugs.php.net/bug.php?id=49510 Also in php.net/ChangeLog-5.php#5.4.8: Bug #49510: Boolean validation fails with FILTER_NULL_ON_FAILURE with empty string or false.Solenoid
WEll, I can tell you it's probably the patch for this one (added in.... 5.4.8, see this commit); (Edit: damn, by searching for the commit, Rocket beat me to it ;) )Greengrocer
Probably Teporary bug - 5.4.7 => NULL already so it was fixed :)Kinzer
It looks like a BC break to me. Let me look at it and will post an update later.Hangeron
U
-3

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

Undamped answered 30/1, 2014 at 23:6 Comment(1)
filter_var() is a bit different. Please see its documentation.Viticulture

© 2022 - 2024 — McMap. All rights reserved.