#37993 [NEW]: integer type conversion behavior is inconsistent

From: Date: Mon, 03 Jul 2006 02:37:54 +0000
Subject: #37993 [NEW]: integer type conversion behavior is inconsistent
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99051@lists.php.net to get a copy of this message
From: shailesh_bavadekar at yahoo dot com Operating system: all PHP version: 5.1.4 PHP Bug Type: *General Issues Bug description: integer type conversion behavior is inconsistent 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. -- Edit bug report at http://bugs.php.net/?id=37993&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37993&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37993&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37993&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37993&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37993&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37993&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37993&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37993&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37993&r=support Expected behavior: http://bugs.php.net/fix.php?id=37993&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37993&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37993&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37993&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37993&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37993&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37993&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37993&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37993&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37993&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37993&r=mysqlcfg

« previous php.bugs (#99051) next »