|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-06-25 11:35 UTC] cmb@php.net
-Status: Open
+Status: Verified
-Type: Feature/Change Request
+Type: Documentation Problem
-Assigned To:
+Assigned To: cmb
[2016-06-25 11:35 UTC] cmb@php.net
[2016-06-25 11:41 UTC] cmb@php.net
[2016-06-25 11:41 UTC] cmb@php.net
-Status: Verified
+Status: Closed
[2016-06-25 11:41 UTC] cmb@php.net
[2020-02-07 06:07 UTC] phpdocbot@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 02:00:01 2025 UTC |
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));