|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50080 1 bit short of an 8 byte integer
Submitted: 2009-11-04 16:14 UTC Modified: 2013-06-03 05:52 UTC
From: aidevelopment at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.11 OS: Linux 2.6.15-26-server
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: aidevelopment at gmail dot com
New email:
PHP Version: OS:


 [2009-11-04 16:14 UTC] aidevelopment at gmail dot com
Despite having PHP_INT_MAX set to 8 bytes, It is impossible to have an int greater than 1000000000000000000000000000000000000000000000000000000000000000.
8 Byte, or 64 bit maximum should be 1111111111111111111111111111111111111111111111111111111111111111.

In my included example, it is clear that when attempting to increase the value above(by adding 1), simply nothing happens.

Attempting to assign a variable to a number greater than the above number produces unpredictable results.

Reproduce code:
echo "Int Size = ".PHP_INT_SIZE." bytes.<br>";
        printf ("status = '%b'<br>", $status);

Expected result:
Int Size = 8 bytes.
status = '111111111111111111111111111111111111111111111111111111111111111'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000001'
status = '1000000000000000000000000000000000000000000000000000000000000010'
status = '1000000000000000000000000000000000000000000000000000000000000011'

Actual result:
Int Size = 8 bytes.
status = '111111111111111111111111111111111111111111111111111111111111111'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000000'
status = '1000000000000000000000000000000000000000000000000000000000000000'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-04 17:17 UTC]
In a 64 bit integer, 1 bit indicates the sign and 63 bits are left for the number. Thus the range is from -2^63 to 2^63, giving 2^64 numbers.
 [2009-11-04 17:59 UTC] aidevelopment at gmail dot com
I understand what you are saying. However, the handling is very difficult to understand. As you can see, adding 1 simply has no effect past positive 0 (1000000000000000000000000000000000000000000000000000000000000000). I have not been able to determine yet exactly what happens when you explicitly assign a variable to a value "too large".

Is there no way to have PHP utilize 64 bit values (uint64)?
 [2009-11-04 22:51 UTC]
 [2009-11-05 01:56 UTC] aidevelopment at gmail dot com
Hi Jani,

Thanks for the update. Please, allow me to clarify my last post.

With the information you've given, we know the 64th bit (far left), is reserved for sign. 

With a simple two line script, we can see that 0 = positive, therefore 1 = negative.

//determine positive vs. negative (observe far left bit).
printf("a = '%b'", $a);

The example below will show the difference between actual expected result when increasing integers past the maximum value of an unsigned int.

//set a equal to the max

//add one

//Expecting a variable wrap here. e.x. $a = -0x7FFFFFFFFFFFFFFF
//Actual result is $a = negative 0
printf("a = '%b'", $a);

//add one

//Given a is now actually equal to negative 0
//Expecting a = 1;
//Actual result is $a = negative 0 (unchanged).
printf("a = '%b'" ,$a);

I would appreciate if you would explain how giving the incorrect answer to a simple mathematical formula (x+1) is not a bug. If this is in fact a bug, please re-open, reassign and/or recategorize this bug appropriately. Thanks!

 [2013-06-02 22:10 UTC] gustav at svalander dot eu
If PHP does not support uint64 then it should be clearly stated in the 
documentation. This crap cost me 8h.
 [2013-06-03 05:52 UTC]
It is quite clearly stated in the documentation exactly where you would expect it 
to be at where it says:

The size of an integer is platform-dependent, although a maximum value of about 
two billion is the usual value (that's 32 bits signed). 64-bit platforms usually 
have a maximum value of about 9E18. PHP does not support unsigned integers.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 02:01:36 2024 UTC