Re: FILTER_VALIDATE_INT - newbie question

From: Date: Wed, 07 Oct 2009 17:30:45 +0000
Subject: Re: FILTER_VALIDATE_INT - newbie question
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-298738@lists.php.net to get a copy of this message
> If I put 0 filter_var() will return false. Actually it returns the integer 0, not the boolean FALSE. Here's an illustration of the difference: http://codepad.org/73wff2u0 The integer value 0 can masquerade as "false" in an if() statement, of course, as Ash pointed out above. > If I put 0342352 filter_var() will also return false. How is 0342352 being assigned to the variable that you're filtering? If PHP thinks it's a string, then the filter will fail. If PHP thinks it's a number, it seems to convert it internally to the number 115946, before you get to the filter. Not sure what's going on there. At any rate it will then pass FILTER_VALIDATE_INT, but the value's not going to be what you expect. You can see it happening here: http://codepad.org/tw2qlpC1 Ben

« previous php.general (#298738) next »