Edit report at http://bugs.php.net/bug.php?id=52884&edit=1
ID: 52884 Updated by: cataphr...@php.net Reported by: marcus at t3sec dot info Summary: FILTER_VALIDATE_INT treats float as integer -Status: Open +Status: Bogus Type: Bug Package: Unknown/Other Function Operating System: Ubuntu 8.04.4 LTS PHP Version: Irrelevant Block user comment: N New Comment: The goal of FILTER_VALIDATE_INT is not to replicate the behavior of is_int. The filter extension aims to validate and sanitize string values. "(double) 10." is converted to the "10" (following the normal conversion to string rules) and that's what is validated as an integer. Notice that "10." (string) is not validated as an integer. Previous Comments: ------------------------------------------------------------------------ [2010-09-18 21:49:05] marcus at t3sec dot info Description: ------------ PHP's filter extension erroneous validates a float (10.) as integer. The observed behaviour in filter extension is not consistent to is_int()/is_float() type checks whereas 10. is reported to be float. In addition, the formal structure of integers *1) does not mention dots to be part of a valid integer. *1) http://www.php.net/manual/en/language.types.integer.php Environment: Server OS: Ubuntu 8.04.4 LTS PHP package in use: 5.2.4-2ubuntu5.10 Test script: --------------- $variableToTest = 10.; echo "This variable type is " . (is_int($variableToTest) ? 'integer' : 'not integer') . "!\n"; echo "This variable type is " . (is_float($variableToTest) ? 'float' : 'not float') . "!\n"; // validate integer echo "This variable is considered to be " . ((FALSE !== filter_var($variableToTest, FILTER_VALIDATE_INT)) ? 'integer' : 'not integer') . "!\n"; echo "This variable is considered to be " . ((FALSE !== filter_var((string)$variableToTest, FILTER_VALIDATE_INT)) ? 'integer' : 'not integer') . "!\n"; // validate float echo "This variable is considered to be " . ((FALSE !== filter_var($variableToTest, FILTER_VALIDATE_FLOAT)) ? 'float' : 'not float') . "!\n"; echo "This variable is considered to be " . ((FALSE !== filter_var((string)$variableToTest, FILTER_VALIDATE_FLOAT)) ? 'float' : 'not float') . "!\n"; Expected result: ---------------- This variable type is not integer! This variable type is float! This variable is considered to be not integer! This variable is considered to be not integer! This variable is considered to be float! This variable is considered to be float! Actual result: -------------- This variable type is not integer! This variable type is float! This variable is considered to be integer! This variable is considered to be integer! This variable is considered to be float! This variable is considered to be float! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52884&edit=1