Edit report at http://bugs.php.net/bug.php?id=54524&edit=1
ID: 54524 User updated by: dosergio at ig dot com dot br Reported by: dosergio at ig dot com dot br Summary: intval doesn't throw warning when value is bigger than the maximum allowed Status: Bogus Type: Bug Package: *General Issues Operating System: all PHP Version: Irrelevant Block user comment: N Private report: N New Comment: So I suggest to change the behaviour. In my opinion, throwing a Warning would be more intelligent than returning 2^31-1. It is an Error because it offends Mathematics. A function with different arguments, in this case should return different results, BUT UP TO NOW, it may return always 2^31-1. Can't anyone else see this ? The way it is today turns PHP into a "hiden bugs" language. Previous Comments: ------------------------------------------------------------------------ [2011-04-19 08:52:45] ahar...@php.net No, it doesn't. This is expected and documented behaviour. ------------------------------------------------------------------------ [2011-04-13 16:17:29] dosergio at ig dot com dot br Description: ------------ If you use intval with an argument that is bigger than 2147483647 the result will always be 2147483647. That's a problem that PHP doesn't throw an Error or Warning, because at the first glance, it looks like a mistery from where comes this magic number ? If someone used intval with an argument that is bigger than 2147483647 IMHO php should die with some message like this: 'Warning: Argument too big for intval. Maximum allowed is 2147483647' or 'Error: Argument too big for intval. Maximum allowed is 2147483647' I lost almost one hour to discover from where the magic number came... If there was the Error or Warning, it would be MUCH EASIER to solve the problem. Test script: --------------- <?php echo intval('11111111111'); ?> Expected result: ---------------- Throwing an Error (die) or Warning showing that the argument passed for intval was TOO BIG. Actual result: -------------- The function does NOT give any type of hint of the problem, and returns a fixed value 2147483647 as result, DOES NOT MATTER what the argument is, as long as it is bigger than 2147483647... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54524&edit=1