php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54524 intval doesn't throw warning when value is bigger than the maximum allowed
Submitted: 2011-04-13 16:17 UTC Modified: 2011-04-19 14:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dosergio at ig dot com dot br Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dosergio at ig dot com dot br
New email:
PHP Version: OS:

 

 [2011-04-13 16:17 UTC] 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...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-19 08:52 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2011-04-19 08:52 UTC] aharvey@php.net
No, it doesn't. This is expected and documented behaviour.
 [2011-04-19 14:21 UTC] dosergio at ig dot com dot br
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 01:01:31 2024 UTC