php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37993 integer type conversion behavior is inconsistent
Submitted: 2006-07-03 02:37 UTC Modified: 2015-01-09 00:28 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: shailesh_bavadekar at yahoo dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.1.4 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: shailesh_bavadekar at yahoo dot com
New email:
PHP Version: OS:

 

 [2006-07-03 02:37 UTC] shailesh_bavadekar at yahoo dot com
Description:
------------
When an integer operand value exceeds 2^32 the php
runtime automatically converts it into float. This
is completely transparent to the applications
dealing with integer arithmetic. It allows PHP
applications to handle integers upto 2^53. (Larger
values don't work correctly due to precision
limits of 64 bit floating point format).

However things are not so clear when numeric
values are initially expressed as strings (e.g.
read from a file or network).

e.g. consider following code -

    <?php

    $i1 = 4294967296;
    $i2 = 2147483647 * 2 + 2;
    $i3 = (integer) 4294967296;
    $i4 = (integer) "4294967296";

    echo  $i1 . "\n"; // prints 4294967296
    echo  $i2 . "\n"; // prints 4294967296
    echo  $i3 . "\n"; // prints 0!
    echo  $i4 . "\n"; // prints 2147483647!!

    ?>

Proposed fix: The "automatic conversion to float"
rule should be uniformly applied in all these
cases even if the program wants to explicitly cast
to integer.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 00:28 UTC] ajf@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2015-01-09 00:28 UTC] ajf@php.net
If someone asks for an integer, they should get an integer.

Converting to float when someone asks for an *integer* would be incredibly counter-intuitive.

Big Integer Support (http://wiki.php.net/rfc) would "resolve" this the way you'd like, though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC