Req #72490 [NEW]: FILTER_VALIDATE_INT: unexpected result for bool and float

From: Date: Fri, 24 Jun 2016 21:10:02 +0000
Subject: Req #72490 [NEW]: FILTER_VALIDATE_INT: unexpected result for bool and float
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201837@lists.php.net to get a copy of this message
From: kzkggaara at mailhouse dot biz Operating system: Ubuntu 14 x64 PHP version: 5.6.23 Package: Filter related Bug Type: Feature/Change Request Bug description:FILTER_VALIDATE_INT: unexpected result for bool and float Description: ------------ When using filter_var(X, FILTER_VALIDATE_INT), where X is: - true - result is int(1) - false - result is bool(false) - 1.1 - result is bool(false) - 0.0 - result is int(0) - '0.0' - result is bool(false) - '-0.0' - result is bool(false) Problems: - Why true is reported as valid 1 but false is invalid? Both are invalid. - Why 0.0 is reported as valid? Other floats are not. - Why the same 0.0 as a string is reported as invalid? This is inconsistent with ints: filter(X = '1') === filter(X = 1), i.e. ints as strings pass as valid. Test script: --------------- // Prints int(1). var_dump(filter_var(true, FILTER_VALIDATE_INT)); // ...but this prints bool(false). var_dump(filter_var(false, FILTER_VALIDATE_INT)); // -------- // Prints bool(false). var_dump(filter_var(1.1, FILTER_VALIDATE_INT)); // ...but this prints int(0). var_dump(filter_var(0.0, FILTER_VALIDATE_INT)); // ...but this again is bool(false). var_dump(filter_var('0.0', FILTER_VALIDATE_INT)); // Also bool(false). var_dump(filter_var('-0.0', FILTER_VALIDATE_INT)); Expected result: ---------------- I expect these to return bool(false): var_dump(filter_var(true, FILTER_VALIDATE_INT)); var_dump(filter_var(0.0, FILTER_VALIDATE_INT)); -- Edit bug report at https://bugs.php.net/bug.php?id=72490&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72490&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72490&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72490&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=72490&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=72490&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=72490&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=72490&r=needscript Try newer version: https://bugs.php.net/fix.php?id=72490&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=72490&r=support Expected behavior: https://bugs.php.net/fix.php?id=72490&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=72490&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=72490&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=72490&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72490&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=72490&r=dst IIS Stability: https://bugs.php.net/fix.php?id=72490&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=72490&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=72490&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=72490&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=72490&r=mysqlcfg

« previous php.bugs (#201837) next »