PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #47718 Missing documentation for 64 bit overflows
Submitted:19 Mar 2:46pm UTC Modified: 19 Nov 11:30am UTC
From:vivekanandan8 at yahoo dot com Assigned to:mattwil
Status:Closed Category:Documentation problem
Version:Irrelevant OS:*
View/Vote Developer Edit Submission

Welcome! If you don't have a SVN 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.
SVN Username: SVN Password:
Quick Fix:
Status: Assign to:
Category:
Summary:
From: vivekanandan8 at yahoo dot com
New email:
Version: OS:
New/Additional Comment:

[19 Mar 2:46pm UTC] vivekanandan8 at yahoo dot com
Description:
------------
Documentation for 64 bit platform about integers overflow 

Reproduce code:
---------------
---
From manual page: language.types.integer
---

Expected result:
----------------
If PHP encounters a number beyond the bounds of the integer type, it
will be interpreted as a float instead. 
This above general rule differs depending on whether a 32 bit or 64 bit
platform is used, which is described in the table below 

 Platform: 32 bit , Range: -2^31-1 and 2^31-1,Numbers: -2147483647 to
2147483647
Platform: 64 bit , Range: -2^63-1 and 2^63-1,Numbers:
-9223372036854775807 to 23372036854775807

<?php
$large_number=9223372036854775807;
var_dump($large_number);
// output: int(9223372036854775807)
$large_number = 9223372036854775808;
var_dump($large_number);
// output: float(9.2233720368548E+18) as 9223372036854775808

//2^64-1 is 18446744073709551615
var_dump(0xffffffffffffffff);
// output: float(1.844674407371E+19) as 18446744073709551615
?>

Actual result:
--------------
No documentation regarding 64 bit platform in online php manual also.i
added these info as add a note even it is not approved. i am interested
in contributing php manual.please do the needful.
[20 Mar 6:49pm UTC] kalle@php.net
Matt, you have worked on some 64bit overflows recently, think you 
could look into this?
[25 Mar 11:20am UTC] vivekanandan8 at yahoo dot com
hi,
  sorry, Please ignore the previous comments.

since in PHP zval for storing integer is long data type.
The Data Representation for long is defined by ABI(Application Binary
Interface)
which says that 

Bit-field Type: signed long, Width(bits)  1to 64,Range:
&#8722;2^w&#8722;1 to 2^w&#8722;1&#8722; 1
for HexaDeciamal Numbers : Width(bits)  1to 64, Range: 0 to 2w&#8722; 1

For integers in PHP:
 
Platform: 32 bit , Range: -2^31 and 2^31-1,Numbers: -2147483648 to
2147483647

Platform: 64 bit , Range: -2^63 and 2^63-1,Numbers:-9223372036854775808
to 23372036854775807

For Hexadeciaml in PHP:

Platform: 32 bit , Range: 0 to 2^32&#8722; 1, Numbers: 0 to 4294967295

Platform: 64 bit , Range: 0 to -2^64-1, Numbers: 0 to 23372036854775807

more info regarding
ABi(http://www.x86-64.org/documentation/abi-0.99.pdf)

Example for 64 bit integer overflow

<?php

$large_number=9223372036854775807;
var_dump($large_number);
// output: 2^63-1 for integer as int(9223372036854775807)

$large_number = 9223372036854775808;
var_dump($large_number);
// output: float(9.2233720368548E+18) as 9223372036854775808

$large_number=-9223372036854775807;
var_dump($large_number);
// output: int(-9223372036854775807)

$large_number =(int)-9223372036854775808;
var_dump($large_number);
// output: 2^64 for integer as int(9223372036854775808)

?>

Example for 64 bit Hexadecimal  overflow
<?
//2^64-1 is 18446744073709551615
var_dump(0xffffffffffffffff);
// output: float(1.844674407371E+19) as 18446744073709551615
?>
[25 Mar 11:29am UTC] vivekanandan8 at yahoo dot com
Hi,
  sorry some character are misdecoded, hence i am giving that onceagain,

Since in PHP zval for storing integer is long data type.
The Data Representation for long is defined by ABI(Application Binary
Interface)
which says that 

Bit-field Type:signed long,Width(bits)1to64,Range:-2^w-1 to(2^w-1)-1
for HexaDeciamal Numbers : Width(bits)  1to 64, Range: 0 to 2^w-1

For integers in PHP:
 
Platform: 32 bit , Range: -2^31 and 2^31-1,Numbers: -2147483648 to
2147483647

Platform: 64 bit , Range: -2^63 and 2^63-1,Numbers:-9223372036854775808
to 23372036854775807

For Hexadeciaml in PHP:

Platform: 32 bit , Range: 0 to 2^32&#8722; 1, Numbers: 0 to 4294967295

Platform: 64 bit , Range: 0 to -2^64-1, Numbers: 0 to 23372036854775807

more info regarding
ABi(http://www.x86-64.org/documentation/abi-0.99.pdf)

Example for 64 bit integer overflow

<?php

$large_number=9223372036854775807;
var_dump($large_number);
// output: 2^63-1 for integer as int(9223372036854775807)

$large_number = 9223372036854775808;
var_dump($large_number);
// output: float(9.2233720368548E+18) as 9223372036854775808

$large_number=-9223372036854775807;
var_dump($large_number);
// output: int(-9223372036854775807)

$large_number =(int)-9223372036854775808;
var_dump($large_number);
// output: 2^64 for integer as int(9223372036854775808)

?>

Example for 64 bit Hexadecimal  overflow
<?
//2^64-1 is 18446744073709551615
var_dump(0xffffffffffffffff);
// output: float(1.844674407371E+19) as 18446744073709551615
?>
[19 Nov 11:30am UTC] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=290980
Log: Usual maximum on 64-bits (bug #47718)
[19 Nov 11:30am UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.


RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC