|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24381 Inconsistence behavior of var_dump
Submitted: 2003-06-28 18:51 UTC Modified: 2003-06-28 19:20 UTC
From: yipkeikwok at yahoo dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.2 OS: Windows 2000, Redhat Linux 9
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.
Block user comment
Status: Assign to:
Bug Type:
From: yipkeikwok at yahoo dot com
New email:
PHP Version: OS:


 [2003-06-28 18:51 UTC] yipkeikwok at yahoo dot com
The function var_dump() returns different data type for -2147483647 and -2147483647-1

--Yipkei Kwok

Reproduce code:
$int1 = -2147483648;
$int2 = -2147483647-1;

Expected result:

The lower bound for data type integer is -2147483647. So, -2147483648 (-2147483647-1) should be regarded as float.

Actual result:

However, -2147483648 (-2147483647-1) is regarded as int.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-28 19:05 UTC]
Your "expected result" is based on an incorrect assumption.

The lower bound for type "integer" on a 32bit platform is in fact -2147483648.
 [2003-06-28 19:20 UTC] yipkeikwok at yahoo dot com
If the lower bound for the type "integer" is -2147483648, then, according to

,var_dump() should have returned -2147483648 as int-typed instead of float-typed.

The actual result now is

--Yipkei Kwok

Integer overflow

If you specify a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, if you perform an operation that results in a number beyond the bounds of the integer type, a float will be returned instead.
 [2003-06-28 21:51 UTC] marcot at tabini dot ca
It actually *is* expected (albeit possibly incorrect) behaviour on behalf of the engine:

Basically, what's happening is that 

$int1 = -2147483648;

is being interpreted as 

$int1 = 0 - 2147483648;

Since 2147483648 cannot be represented as an integer value, it (and, therefore, the result of the expression) is converted to double.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 20:01:31 2024 UTC