Re: FILTER_VALIDATE_INT - newbie question

From: Date: Wed, 07 Oct 2009 17:36:52 +0000
Subject: Re: FILTER_VALIDATE_INT - newbie question
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-298739@lists.php.net to get a copy of this message
> 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 Sorry, brain fart. In PHP, a leading 0 in an integer indicates an octal number (thanks, Martin). PHP immediately converts it to decimal internally. Hence 0342352 becomes 115946. But it's a bit of a fluke that the example you used happened to be a valid octal number. Try something that starts with 0 and has an 8 or a 9 in it; you'll end up with plain old 0 (presumably because PHP's internal attempt to convert from octal, fails): http://codepad.org/KBUgAZWJ Which, of course, leads to the apparent-false discussed above. Ben

« previous php.general (#298739) next »